linux - 将每 n 行转置为一行

标签 linux shell awk sed paste

我想把一堆 n 行合并成一行,不知道该怎么做。任何帮助表示赞赏。

一堆 11 个单词,然后是一个空行,然后是一堆 ll 个单词,然后是空白,就像...等等。

示例:

cat filename

hi
hello
how
are
you
i
am
fine
how
are
you

hi
how
is
she
doing
i 
have
not 
herd 
from
her

..
..

期望的输出:

cat newFile

hi hello how are you i am fine how are you 
hi how is she doing i have not heard from her 
..
..

最佳答案

通过 awk。

$ awk -v RS= '{gsub(/\n/, " ")}1' file
hi hello how are you i am fine how are you
hi how is she doing i  have not  herd  from her

关于linux - 将每 n 行转置为一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29841404/

相关文章:

linux - 如何在linux中递归计算某些文件的总大小

linux - 如何在 Linux 终端中删除 CRLF 字符(回车换行符)?

awk - 在偶数行中计算 b 或 B

linux - awk 中的 printf 格式说明符不适用于多个参数

c - 使用 C 在 Linux shell 中实现输入/输出重定向

python - 创建逗号分隔的路径列表(允许路径中存在空格),并将结果作为变量传递以供再次使用

linux - 可以从 perf.data 文件生成 perf-stat 结果吗?

linux - awk 没有使用 bash 变量

linux - sudo dpkg -i mod-pagespeed-*.deb 给出 "not a debian format archive"错误

linux - 使用 inotify-tools 作为守护进程处理数据