Dear Rudic,
Could you please teach me how to catch the fish.
I looked up sed -help before opening this thread, but there was no info regarding n and p and other letters.
I'd appreciate if you would let us know how to find more info regarding functions of this notations
My wisdom comes from the man pages: man sed , plus, infrequently, info sed .
And, DON'T forget, regular consumption of these forums! Many a trick I learned in here. Above little one copies a line into the hold buffer (h), reads the next line (n), appends from the hold buffer (G), and prints (p). It depends on the lines always coming in pairs.
If, instead of switching every pair of lines in a file, you wanted to switch every line containing the string wget with the line preceding it, you could try:
ed -s input_file <<-EOF
g/wget/ .-1m.
,p
Q
EOF
And, if after switching the order of those pairs of lines you also want to join them, you could try: