jimmyf
1
have some data and I'm attempting to manipulate with sed with not much success.
Name
John Davis
Phone
5555555
Name
Tim Watson
Phone
1111111
would like to get that data to sort like this
John Davis 5555555
Tim Watson 1111111
gotten sed to search for the value below 'Name' and 'Phone but can't seem to manipulate it further. Any help would greatly be appreciated.
sed -n '/Name/{n;p;}'
sed -n '/Phone/{n;p;}'
RudiC
2
What would your further manipulation look like? An upper case N
(in lieu of the n
) would suffice to get what have in your desired output...
jimmyf
3
Rudi, that only achieved this:
John Davis
5555555
not exactly, but:
awk '{$1="";printf("%s%s", $0, (FNR%2)?OFS:ORS)}' RS= myFile
or better yet:
awk '{printf("%s%s", $2, (FNR%2)?OFS:ORS)}' FS='\n' RS= myFile
RudiC
5
Sorry, yes - that was a bit short sighted; I could not test it as I was away from my computer.
For exactly the given input, try
sed -n '/Name/{n;x;}; /Phone/{n;H;x; s/\n/ /; p}' file
John Davis 5555555
Tim Watson 1111111
1 Like
In sed you must combine the two lines into one buffer.
Something like this, yet untested
sed -n '
/^Name/{n;h;}
/^Phone/{n;x;G;s/\n/ /;p;}
'