|
||||||||||
|
|
||||||||||
NavigationMy posts on Twitter
|
Concatenating lines with sedSuppose you have the following file: AA 123 BB 456 CC 789 And you want to transform it into the following: AA; 123 BB; 456 CC; 789 This can easily be achieved by using the Linux command /^[[:alpha:]][[:alpha:]]$/ {
N
s/^\(.*\)\n\(.*\)$/\1; \2/
p
}When the input text is saved in a file with name The sed script is a fact fairly easy to understand. On the first line we match every line that consists of 2 alphabetic characters. When we have such a match, the lines 2, 3 and 4 will be executed. On line 2 we read the next line of the file and append it to the currently read line. On line 3, we remove the newline character from the input and replace it with the dot-comma followed by a space. On line 4, we print the text. |
|
||||||||
| © Copyleft 2005-2011 - Lode Vanstechelman - Login | ||||||||||