$ cat fileSTARTUnixLinuxSTARTSolarisAixSCO 1. Join the lines following the pattern START without any delimiter.
$ awk '/START/{if (NR!=1)print "";next}{printf $0}END{print "";}' fileUnixLinuxSolarisAixSCO 2. Join the lines following the pattern START with space as delimiter.
$ awk '/START/{if (NR!=1)print "";next}{printf "%s ",$0}END{print "";}' fileUnix LinuxSolaris Aix SCO 3. Join the lines following the pattern START with comma as delimiter.
$ awk '/START/{if (x)print x;x="";next}{x=(!x)?$0:x","$0;}END{print x;}' fileUnix,LinuxSolaris,Aix,SCO 4. Join the lines following the pattern START with comma as delimiter with also the pattern matching line.
$ awk '/START/{if (x)print x;x="";}{x=(!x)?$0:x","$0;}END{print x;}' fileSTART,Unix,LinuxSTART,Solaris,Aix,SCO 5. Join the lines following the pattern START with comma as delimiter with also the pattern matching line. However, the pattern line should not be joined.
$ awk '/START/{if (x)print x;print;x="";next}{x=(!x)?$0:x","$0;}END{print x;}' fileSTARTUnix,LinuxSTARTSolaris,Aix,SCO 6. Other ways:
paste -d, -s file
cat file | xargs
REF:
http://www.theunixschool.com/2012/05/awk-join-or-merge-lines-on-finding.html
https://stackoverflow.com/questions/15758814/turning-multiple-lines-into-one-line-with-comma-separated-perl-sed-awk
==========================================================
AC M07451
ID V$PBX1_10NA PBX1AC M07452ID V$MEIS1_06NA Meis1AC M07453ID V$MEIS1BHOXA9PBX1A_01NA Meis1b:Hoxa9:Pbx1aAC M07454ID V$GLI1_Q3_01NA Gli1AC M07455ID V$GLI2_Q3NA Gli2AC M07456ID V$HOXA913_Q4NA HOX 9-13awk '$0 ~ /^AC|^ID|^NA/' conserved.new \
| awk '/AC /{if (x)print x;x="";}{x=(!x)?$0:x","$0;}END{print x;}' \
| sed 's/AC //g' | sed 's/,ID /\t/g' | sed 's/,NA /\t/g' \
> genesymbol
M07451 V$PBX1_10 PBX1M07452 V$MEIS1_06 Meis1M07453 V$MEIS1BHOXA9PBX1A_01 Meis1b:Hoxa9:Pbx1aM07454 V$GLI1_Q3_01 Gli1M07455 V$GLI2_Q3 Gli2==========================================================
more file
start111aabbccstart222ddeeawk '/start/{if (x)print x;x="";}{x=(!x)?$0:x","$0;}END{print x;}' file > bbb
more bbbstart111,aa,bb,ccstart222,dd,eeawk -F"[|, ]" '{for(i=2;i<=NF;i++){print $1"|"$i}}' bbb
start111|aastart111|bbstart111|ccstart222|ddstart222|ee