$ cat file
START
Unix
Linux
START
Solaris
Aix
SCO 1. Join the lines following the pattern START without any delimiter.
$ awk '/START/{if (NR!=1)print "";next}{printf $0}END{print "";}' file
UnixLinux
SolarisAixSCO 2. Join the lines following the pattern START with space as delimiter.
$ awk '/START/{if (NR!=1)print "";next}{printf "%s ",$0}END{print "";}' file
Unix Linux
Solaris 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;}' file
Unix,Linux
Solaris,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;}' file
START,Unix,Linux
START,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;}' file
START
Unix,Linux
START
Solaris,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_10
NA  PBX1
AC  M07452
ID  V$MEIS1_06
NA  Meis1
AC  M07453
ID  V$MEIS1BHOXA9PBX1A_01
NA  Meis1b:Hoxa9:Pbx1a
AC  M07454
ID  V$GLI1_Q3_01
NA  Gli1
AC  M07455
ID  V$GLI2_Q3
NA  Gli2
AC  M07456
ID  V$HOXA913_Q4
NA  HOX 9-13

awk '$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    PBX1
M07452    V$MEIS1_06    Meis1
M07453    V$MEIS1BHOXA9PBX1A_01    Meis1b:Hoxa9:Pbx1a
M07454    V$GLI1_Q3_01    Gli1
M07455    V$GLI2_Q3    Gli2
==========================================================

more file
start111
aa
bb
cc
start222
dd
ee

awk '/start/{if (x)print x;x="";}{x=(!x)?$0:x","$0;}END{print x;}' file > bbb

more bbb
start111,aa,bb,cc
start222,dd,ee

awk -F"[|, ]" '{for(i=2;i<=NF;i++){print $1"|"$i}}' bbb
start111|aa
start111|bb
start111|cc
start222|dd
start222|ee

Linux/shell: Concatenate multiple lines to one line的更多相关文章

  1. linux shell unzip multiple zip files

    find . -name "*.result.zip" | xargs -n 1 unzip - -P password -d ../ext_logs

  2. Bash For Loop Examples for Your Linux Shell Scripting--ref

    There are two types of bash for loops available. One using the “in” keyword with list of values, ano ...

  3. linux shell命令之wc/split及特殊字符

    [时间:2018-07] [状态:Open] [关键词:linux, wc, split, 通配符,转义符,linux命令] 0 引言 整理这篇文章的目的不是为了什么学习,仅仅是为了强化下记忆,以便下 ...

  4. Linux Shell基础(下)

    Linux Shell基础(下) 目录 一.shell特殊符号cut命令 二.cut.sort.wc.uniq命令 三.tee.tr.split命令 四.简易审计系统 五.fork, exec, so ...

  5. Linux Shell 裡一些很少用到卻很有用的指令

    Linux Shell 裡一些很少用到卻很有用的指令 2009年11月30日 13:53:00 yaoyasong 阅读数:414   Linux Shell 裡一些很少用到卻很有用的指令 你是不是已 ...

  6. Linux shell下30个有趣的命令

    Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...

  7. linux shell 总结 (整理)

    ls /usr/bin/ info #路径操作 dirname basename #“”和‘’与 ` ` 在shell变量中的区别 “ ” 允许通过$符引用其他变量 ‘’禁止引用其他变量符,视为普通字 ...

  8. LINUX SHELL脚本攻略笔记[速查]

    Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述 ...

  9. Linux-(3)Linux Shell 使用

    三.Linux Shell 3.1 文件管理 3.1.1 ls 命令 显示指定工作目录下的内容及属性信息 ls 命令是Linux下最常用的指令之一.ls命令为英文单词 list 的缩写,正如英文单词 ...

随机推荐

  1. html5-基本知识小结及补充

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  2. sitecore系列教程之Sitecore个性化-体验概况概述

    SITECORE 8:体验概况概述 什么是体验简介? 体验配置文件是Sitecore中的仪表板应用程序,它说明了客户体验和交互的关键区域,例如访问者详细信息,访问,活动,目标,配置文件,自动化等等. ...

  3. QT构建窗体(父窗体传为野指针)异常案例

    [1]源码 工作中,时常会遇到各种各样的异常场景,有些异常场景很常见,必要备录,以防再犯. 分享本案例为:QT创建窗体时parent父窗体传野指针引起异常. 本案例源码如下: 1.1 默认新建一个QT ...

  4. POJ 2492 A Bug's Life (并查集)

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  5. Codeforce 270A - Fancy Fence (正多边形)

    Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fe ...

  6. Installing Android Studio

    To set up Android Studio on Windows: Launch the .exe file you just downloaded. Follow the setup wiza ...

  7. springboot打包部署到tomcat

    一. springboot打成war包: 1. 首先查看是否为war 2. File----->ProjectStruture,选择Artifacts,中部点击“+”号 3. 按图中标记进行选择 ...

  8. Java编译报错:意外的类型

    先上代码 后续更新 public class IncidentType { public static void main(String[] args) { int a = 3; int b = ++ ...

  9. java类中使用quartz,设置自动任务Demo

    package com.tech.jin.jobScheduler; import java.text.ParseException; import java.util.ArrayList; impo ...

  10. scrapy 去重 dont_filter=False

    yield Request(...... dont_filter=False)