I would like to remove all the newline character that occurs after a partiular string and replace it with a tab space. Say for instance my sample.txt is as follows
foo
bar bar bar bar some text
I would like it to be
foo bar bar bar bar some text
How do I do this via bash/awk/sed. Do help.
Use printf() when you want awk without printing newline AWK printf duplicates the printf C library function writing to screen/stdout.
In awk:
awk '/foo$/ { printf("%s\t", $0); next } 1'
Here is how:
cat input.txt | sed ':a;N;$!ba;s/foo\n/foo\t/g'
More about why simple sed 's/foo\n/foo\t/g'
does not work here: http://linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/sedfaq5_009.html
perl -pe 's/(?<=foo)\n/\t/' input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With