$ 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. jquer文字闪烁简单实现

    arguments.callee <script type="text/javascript"> (function () { $(".usesend&quo ...

  2. html5-颜色的表示

    div{width: 100%;height: 100px;}body{background: url(../pic/2.png);}/*#div1{background: #ff0000;}#div ...

  3. 20155228 实验三 敏捷开发与XP实践

    20155228 实验三 敏捷开发与XP实践 实验内容 1. XP基础 2. XP核心实践 3. 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)>& ...

  4. 字符编码几个缩写 ACR CCS CEF CES TES

    摘自https://zhuanlan.zhihu.com/p/27012967 5. 在Unicode Technical Report (UTR统一码技术报告) #17<UNICODE CHA ...

  5. 20165305 苏振龙《Java程序设计》第二周学习总结

    代码托管(ch2,ch3) 脚本截图 教材内容总结 类型.变量与运算符 基本类型 整数(short.int.long) 字节(byte) 浮点数(float/double) 字符(char)将一个数字 ...

  6. MongoDB优化,建立索引实例及索引机制原理讲解

    MongoDB优化,建立索引实例及索引机制原理讲解 为什么需要索引? 当你抱怨MongoDB集合查询效率低的时候,可能你就需要考虑使用索引了,为了方便后续介绍,先科普下MongoDB里的索引机制(同样 ...

  7. 以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明

    以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明 为了让你的Ðapp运行上以太坊,一种选择是使用web3.js library提供的web3.对象.底层实 ...

  8. kivy中bind的使用

    一般在kivy中使用bind()来绑定回调函数,所谓回调函数,个人理解就是一个预先定义好的方法, 因为APP是静态的, 需要等待用户进行操作, 特定的操作背后都绑定了特定的回调函数, 一般有两种类型: ...

  9. P3332 [ZJOI2013]K大数查询(线段树套线段树+标记永久化)

    P3332 [ZJOI2013]K大数查询 权值线段树套区间线段树 把插入的值离散化一下开个线段树 蓝后每个节点开个线段树,维护一下每个数出现的区间和次数 为了防止MLE动态开点就好辣 重点是标记永久 ...

  10. The address where a.out.debug has been loaded is missing以及No symbol "*" in current context原因与解决方法

    最近,在debug core的时候,发现p 变量的时候提示“No symbol "*" in current context”,我们的代码使用-g编译的,经查有可能是下列几个原因或 ...