Hello All,
I need help with the below, I would appreciate any tip.
I have a file as below
Input file
Apple: Green
Banana: Yellow
Grapes: Black
Apple: Red
Banana: Green
Grapes: Green
Grapes: Brown
Apple: Pale Red
Banana: Greenish yellow
Grapes: Brown
Apple: Yellowish Red
Banana: Pale Brown
Grapes: BlackSeedless
Output file:
---------------
Apple: Green
Banana: Yellow
Grapes: Black
---------------
Apple: Red
Banana: Green
Grapes: Green
Grapes: Brown
---------------
Apple: Pale Red
Banana: Greenish yellow
Grapes: Brown
---------------
Apple: Yellowish Red
Banana: Pale Brown
Grapes: BlackSeedless
i.e. I want to add a header "-------" at start of the line with Apple, like the file should add header when it sees Apple.
root@test1:/tmp# cat fru
Apple: Green
Banana: Yellow
Grapes: Black
Apple: Red
Banana: Green
Grapes: Green
Grapes: Brown
Apple: Pale Red
Banana: Greenish yellow
Grapes: Brown
Apple: Yellowish Red
Banana: Pale Brown
Grapes: BlackSeedless
root@test1:/tmp# sed 's/^Apple:/---------------\n&/' fru
Apple: Green
Banana: Yellow
Grapes: Black
Apple: Red
Banana: Green
Grapes: Green
Grapes: Brown
Apple: Pale Red
Banana: Greenish yellow
Grapes: Brown
Apple: Yellowish Red
Banana: Pale Brown
Grapes: BlackSeedless
Yahoo! it works but, I still see that Apple is not taking a new line?
It is on same line as dashes (----------).
root@test1:/home/user1# sed 's/Apple:/---------------\n&/' /tmp/fru
---------------nApple: Green
Banana: Yellow
Grapes: Black
---------------nApple: Red
Banana: Green
Grapes: Green
Grapes: Brown
---------------nApple: Pale Red
Banana: Greenish yellow
Grapes: Brown
---------------nApple: Yellowish Red
Banana: Pale Brown
Grapes: BlackSeedless
That's most unfortunate.
You have a version of sed that does not like or support escape characters.
You do not have Perl.
What else do we have?
Do you have awk?