A sample to merge continuous text line using awk utility.
i.e, when a text line is ended with a dash ('-'), it should continue with next line.
For example:
1: 11 2: 22 - 3: 33 4: 44
should be merged to:
1: 11 2: 22 33 3: 44
The awk script:
#!/bin/ksh INPUT=${1} awk ' function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s } function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s } function trim(s) { return rtrim(ltrim(s)); } BEGIN {} { # If the last char is a dash, continue if (substr($0, length($0), 1) == "-") { printf "%s ", rtrim(substr($0, 0, length($0) - 1)) } else { printf "%s\n", ltrim($0) } } END {} ' $INPUT
The End.