[=129Dytt.....===..
Sometxt
\Start\now\fine step
watch this space for tools
ends here
=--2323UT;;;====.......
\Start\then\go language again
cubernates space
sign in done
line again
do it now
I need to search line which starts with
\Start
and read next line till it gets blank line and join them all. I need to trim any trailing spaces for each line.So output.txt should be..
\Start\now\fine stepwatch this space for toolsends here
\Start\then\go language againcubernates spacesign in doneline againdo itnow
I tried ..
sed -n '^//Start/{
s/[ \t]*$// # trim trailing spaces
N # Move to next line
s/\n//p #join line and print them
But it goes to next line not beyond. Not sure how to keep lines in buffer till blank line comes.
Tried AWK
sed -i 's/[ \t]*$//g' f1.txt ; gawk '/^\\Start/{gsub("[\n]","",$0);print $0}RS=""' f1.txt
This gives me only last part
\Start\then\go language againcubernates spacesign in doneline againdo itnow
You can try this, it is probably a lot more complicated that in needs to be but it seems to work. It trims the leading spaces before \Start as well so if that is undesired then it can be changed.
Yes that could be done, but then you need to test inside as well which is the case, so here I think it is not that practical. I did not use /^$/ since that would not work with your sample, seeing as its "empty lines" contain spaces. So I used !NF instead .
sed -rn 's/^ *| *$//; / *\\Start/,/^$/ {H; /^$/ {g;s/\n//g;p;s/.*//;h; };}; $ {g;s/\n//g;p;}' file
\Start\now\fine stepwatch this space for tools ends here
\Start\then\go language againcubernates space sign in done line againdo it now
Thanks Rudi.. this is what i was looking for. To understand your code I have gone through Sed documentation and it clears many of my doubts that how sed processes data line by line and only Pattern buffer is used to manipulate while HOLD buffer is used just keep data for future reference...Thanks again