使用awk提取包含空格的列 [英] Using awk to extract a column containing spaces
本文介绍了使用awk提取包含空格的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种从以下输出中提取文件名列的方法。
I'm looking for a way to extract the filename column from the below output.
2016-02-03 08:22:33 610540 vendor_20160202_67536242.WAV
2016-02-03 08:19:25 530916 vendor_20160202_67536349.WAV
2016-02-03 08:17:10 2767824 vendor_20160201_67369072 - cb.mp3
2016-02-03 08:17:06 368928 vendor_20160201_67369072.mp3
其中一个文件的名称中包含空格,这会导致我当前的命令出现问题
One of the files has spaces in the name which is causing issues with my current commmand
awk '{print $4}'
推荐答案
awk
急救!
$ awk '{for(i=4;i<NF;i++) printf "%s", $i OFS;
printf "%s", $NF ORS}' file
vendor_20160202_67536242.WAV
vendor_20160202_67536349.WAV
vendor_20160201_67369072 - cb.mp3
vendor_20160201_67369072.mp3
或
$ awk '{for(i=5;i<=NF;i++) $4=$4 OFS $i; print $4}' file
如果文件格式是固定的,也许使用结构是更好的主意
if your file format is fixed perhaps using the structure is a better idea
$ cut -c36- file
vendor_20160202_67536242.WAV
vendor_20160202_67536349.WAV
vendor_20160201_67369072 - cb.mp3
vendor_20160201_67369072.mp3
这篇关于使用awk提取包含空格的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文