Your code doesn't make an exception for lines containing libname , db2 and datasrc that already end with a semicolon. It doesn't verify that libname is at the start of a line, doesn't verify that db2 is in the 3rd field, and looks for a colon immediately followed by a semicolon (which never appears in your sample input) to end the set of lines being joined.
The awkIGNORECASE variable works in some versions of awk , but it is not in the standards and several standards-conforming versions of awk (including the awk on BSD and OS X systems) do not provide that extension. The code above works with any standards-conforming version of awk , but obviously needs more complicated regular expressions to perform case-insensitive matches.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xgp4/bin/awk or nawk .
I did modify to use IGNORECASE=1 and it handled case differences OK.
I also added the code to be in a loop so it will made the code changes to all code beginning with a given prefix.
#!/bin/ksh
#Combine lines that start with "libname VALUE db2 datasrc" and does not end in semicolon
for f in pre*; do
awk 'BEGIN{IGNORECASE=1} /libname/&&/DB2/ && $0 !~ /;$/ {
printf("%s ", $0)
j = 1
next
}
j { for(i = 1; i < NF; i++)
printf("%s ", $i)
printf("%s%s", $NF, (j = ($NF !~ /;$/)) ? " " : "\n")
next
}
1' "$f" > fifo &&
mv fifo $f
done