避免使用 Cut 计算定界符
Avoid Counting a Delimiter with Cut
我有一个看起来像这样的文件;
"id","string"
"10","john smith"
"20","smith, john"
关于这个我运行cut -d , -f 2
,其中returns
"john smith"
"smith"
第二行,我要return"smith, john"
。是否有解决方案使用 cut
确保指定的定界符在包含在一对双引号内时不被视为一个?
使用:
cut -d , -f 2- file
输出:
"string"
"john smith"
"smith, john"
awk -F'",' 'NR>1 {print }' file
"john smith"
"smith, john"
简而言之:NR>1 跳过第一行并通过 -F'",' 更改字段分隔符可以打印第二行 field/column。
我有一个看起来像这样的文件;
"id","string"
"10","john smith"
"20","smith, john"
关于这个我运行cut -d , -f 2
,其中returns
"john smith"
"smith"
第二行,我要return"smith, john"
。是否有解决方案使用 cut
确保指定的定界符在包含在一对双引号内时不被视为一个?
使用:
cut -d , -f 2- file
输出:
"string" "john smith" "smith, john"
awk -F'",' 'NR>1 {print }' file
"john smith"
"smith, john"
简而言之:NR>1 跳过第一行并通过 -F'",' 更改字段分隔符可以打印第二行 field/column。