我有一个包含8列的tsv文件,只需将第7列剪切并粘贴到另一个txt文件中
in.tsv:
API Admin1 Admin2 Admin3 Admin4 Admin5 Request Response_Code
v1/customers 200 401 401 401 401 { "customer": { "name": "abc", "email":"mailme2@xxx.com","account_classification": "xyz"} } 200
我尝试了以下命令:
paste -d, in.tsv | awk -F, -v OFS=',' '{print $7}'
cat in.tsv | cut -d \, -f 7 > out.txt
awk -F"," '{print $7}' in.tsv > out.txt
使用上述命令,我只能复制第一行。
输出应与in.tsv相同
out.txt:
{ "customer": { "name": "abc", "email":"mailme2@xxx.com","account_classification": "xyz"} }
答案 0 :(得分:0)
响应内部有一个,
,因此字段7将在此时停止。
当您不希望使用真正的解析器时,可以删除前6个和最后一个字段。
测试数据:
API,Admin1 ,Admin2 ,Admin3 ,Admin4 ,Admin5 ,Request ,Response_Code,,
v1/customers,200,401,401,401,401,{ "customer": { "name": "abc", "email":"mailme2@xxx.com","account_classification": "xyz"} },200
v1/customers,200,401,401,401,401,{ "customer": { "name": "def", "email":"mailme2@xxx.com","account_classification": "xyz"} },200
v1/customers,200,401,401,401,401,{ "customer": { "name": "g,h", "email":"mailme2@xxx.com","account_classification": "xyz"} },200
命令:
sed -r 's/([^,]*,){6}//;s/,[^,]*$//' testdata
备注:
标题行具有一个附加,
,因此将在错误的字段7中显示。