![]() ![]() no further input line is read into the pattern space after the 1st one is read into it, unless the last one is read in, but then there's no further line to read in, and the implicit p command is executed.ta makes the end of the script reachable only when the last line of input is read (the only line where s fails), so.s/\n/ / (in principle executed on any line) is successful on any line but the last one, so.N is, in principle, executed on any line, but.:a is just a label, not a command to be executed.sed reads the lines of the input file one by one in order, starting from the 1st line.if the substitution occurred, the execution jumps to step 1 without "hitting" the end of script, i.e. ta goes to the script line following the label :a as long as the substitution in step 2 was successful, i.e.s/\n/ / substitute the newline character \n generated by N with a space.N appends the next line to the (multiline) pattern space, which contains the current line already. ![]() Which is clearer if written as follows, sed -i ':a Improving other answers, one gets sed -i ':a N s/\n/ / ta' file There's no need to put the label :a outside of the main instruction, neither is the -e option necessary needed finally, the /$/ is superfluous (every line has an EOL character). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |