linux - 如何在 linux 中按指定条件将文件中的两行合并为一个?

标签 linux awk sed

我有一个文件,它是使用命令 select into outfile 从 mysql 导出的,由“\”转义...但是,在某些字段中有换行符导致断行,即 mysql 中的记录被分成两行导出的文件。仔分割析,我发现断线以“\”结尾。所以我想将这样的行合并到下一行。我该怎么做?

示例输入:

hello
world\
Thank
you\
are
awesome

输出:

hello
worldThank
youare
awesome

文件有点大,10GB左右。

最佳答案

使用 sed:

sed 'N;s/\\\n//;P;D;' file

关于linux - 如何在 linux 中按指定条件将文件中的两行合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46841170/

相关文章:

linux - 安装 vagrant 时出错 - Sudo apt-get install Vagrant 返回错误 : packages have unmet dependencies - Ubuntu 19. 04

node.js - 无法从 npm 安装最新的软件包版本

linux - 如何移动角色(在 sed 中?)

csv - 使用 sed 填充 CSV 中的空白字段

linux - 计算可打印字符

linux - 如何在 aws 上管理大量 cloudformation 模板/堆栈?

shell - Unix shell : replace by dictionary

linux - 使用 sed - shell 脚本将值 append 到变量

bash - awk、System() 函数、与 shell 交互

linux - 如何使用 sed/awk/perl 从特定列中删除 n 个字符