i am working with a task right now, manipulating text in Unix, but i have no idea how i will do it. I am planning to use sed. this is wat i am trying to do.
I have this text.
BS111
xxxxx
yyyyy
zzzzz
BS112
xxxxx
yyyyy
zzzzz
BS113
xxxxx
yyyyy
zzzzz
so on.. with this kind of format
and i want it to be like:
BS111 xxxxx
BS111 yyyyy
BS111 zzzzz
BS112 xxxxx
BS112 yyyyy
BS112 zzzzz
BS113 xxxxx
BS113 yyyyy
BS113 zzzzz
so on.. with this kind of format
the BS* and its data occurs almost hundred times. so i think the best way to do it is to use a script. thank you in advance for your help.
With awk :
awk '/^BS/{v=$0;next} {print (/^$/) ? $0 : v, $0}' file.txt
BS111 xxxxx
BS111 yyyyy
BS111 zzzzz
BS112 xxxxx
BS112 yyyyy
BS112 zzzzz
BS113 xxxxx
BS113 yyyyy
BS113 zzzzz
This might work for you (GNU sed):
sed -r '/^BS/{h;d};/./!b;G;s/(.*)\n(.*)/\2 \1/' file
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