I have problem with my sed script. I process this data using the above script.
The problem is that, the lines from script:
/^$/d
s/ $/ajes/g
doesn’t work. Of course it will work if I process data again.
This doesn’t work:
sed -f script.sed -i data.file
but this will work (double procesing):
sed -f script.sed -i data.file
sed -f script.sed -i data.file
Why is that? Where is problem? Why I can’t process it once with all results?
The real problem is that you have just one line. And
sedreads it once and tries execute each command one by one, while the whole line is in the patterns space. When you substitute something to\nit is still just one string and it is in the pattern space. It wasn’t divided in multiple strings and reread one by one.Obviously
/^$/doesn’t match to your\n\nands/ $/ajes/gdoesn’t match to your any space before\n. That’s the reason why that doesn’t work the way you expect.You can solve the problem with modifying “non working” commands to