linux - 使用 CSV 文件中的换行符重新格式化项目

标签 linux bash shell

我有一个 csv,我想知道如何用 - 替换换行符,就在 brothers 列中,用 庆典:

name,brothers,age,adress
------------------------
john,"marc
peter
paul
alex",18,street
thomas,mike,20,place

最佳答案

Awk 非常适合这个

 awk -v RS='^$' -v ORS= '{while ( match($0,/"[^"]+"/,a) ) {gsub(/\n/," ",a[0]); print substr($0,1,RSTART-1) a[0]; $0=substr($0,RSTART+RLENGTH)} print}' your.csv

输出:

me,brothers,age,adress
------------------------
john,"marc peter paul alex",18,street
thomas,mike,20,place

关于linux - 使用 CSV 文件中的换行符重新格式化项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43212482/

相关文章:

用于在启动时运行的文件的 Linux 文件安装程序

C : shmget with a 2D array

linux - 从 linux 命令在屏幕上获取输出

linux - 如何在Linux终端中删除 "copy"文件夹

shell - 用于删除旧日志文件的 Unix shell 脚本

regex - 使用 sed 添加空格

Java 原子文件在断电时移动重复文件

java - 如何从命令行查找有关 OpenJDK 提供程序的详细信息

bash - 编写没有 shebang 行的 Bash 脚本

linux - 变量是如何通过 PAM 认证系统传递的