Bash 使用sed(或类似工具)删除重复模式之间的任何内容
我基本上是试图在CSV中“整理”大量数据。我不需要“引号”中的任何信息 尝试了Bash 使用sed(或类似工具)删除重复模式之间的任何内容,bash,awk,sed,non-greedy,Bash,Awk,Sed,Non Greedy,我基本上是试图在CSV中“整理”大量数据。我不需要“引号”中的任何信息 尝试了sed's/“*”/“/”,但如果有多个节在一起,它会删除逗号 我想从中得到: 1,2,"a",4,"b","c",5 为此: 1,2,,4,,,5 是否有sed向导可以提供帮助?:) 您可以使用 sed 's/"[^"]*"//g' file > newfile 见: s='1,2,“a”,4,“b”,“c”,5' sed的//“[^”]*”//g'请您尝试以下内容 awk -v s1="\"" 'BEG
sed's/“*”/“/”
,但如果有多个节在一起,它会删除逗号
我想从中得到:
1,2,"a",4,"b","c",5
为此:
1,2,,4,,,5
是否有sed向导可以提供帮助?:) 您可以使用
sed 's/"[^"]*"//g' file > newfile
见:
s='1,2,“a”,4,“b”,“c”,5'
sed的//“[^”]*”//g'请您尝试以下内容
awk -v s1="\"" 'BEGIN{FS=OFS=","} {for(i=1;i<=NF;i++){if($i~s1){$i=""}}} 1' Input_file
awk-vs1=“\””使用Perl开始{FS=OFS=“,”}{for(i=1;i:
perl -p -e 's/".*?"//g' file
?
强制*
不贪婪
输出:
1,2,,4,,,5
1,2,,4,,,5
请参阅wrt为什么您的尝试失败sed's/“//g”文件
所有3个解决方案都有效-谢谢大家。刚刚发现一个曲线球,在某些行中有换行符-只需删除这些,我就可以排序:)
awk -v s1="\"" ' ##Starting awk program from here and mentioning variable s1 whose value is "
BEGIN{ ##Starting BEGIN section of this code here.
FS=OFS="," ##Setting field separator and output field separator as comma(,) here.
}
{
for(i=1;i<=NF;i++){ ##Starting a for loop which traverse through all fields of current line.
if($i~s1){ ##Checking if current field has " in it if yes then do following.
$i="" ##Nullifying current field value here.
}
}
}
1 ##Mentioning 1 will print edited/non-edited line here.
' Input_file ##Mentioning Input_file name here.
perl -p -e 's/".*?"//g' file
1,2,,4,,,5