我有4列CSV文件:印刷线
01, cat, animal, it catches mice
- 该文件包含来自UTF-各种语言的字符8。
如何在第2列中只打印包含正好2个字符的行,同时还与第4列中该行上任何位置的模式“/ to”匹配?
我有4列CSV文件:印刷线
01, cat, animal, it catches mice
如何在第2列中只打印包含正好2个字符的行,同时还与第4列中该行上任何位置的模式“/ to”匹配?
您可以使用AWK:
$ cat /tmp/l
01, cat, animal, it catches mice
02, ok, aaa, e/tomos
03, bad, qux, vb/tomos
$ awk -F"," 'length($2) == 3 && $4 ~ /\057to/' /tmp/l
02, ok, aaa, e/atmos
试试这个:
egrep "[^,]+,\s+[^,]{2},|([^,]+,\s+){3}.*/to.*" your_file
尝试使用这个文件:
01, cat, animal, it catches mice
01, ab, animal, it catches/o mice
01, ca, animal, it catches/to mice
01, cat, animal, it catches m/toice
,并返回:
01, ab, animal, it catches/o mice
01, ca, animal, it catches/to mice
01, cat, animal, it catches m/toice
这可能适合你:
sed '/^[^,]*,\s*..,[^,]*,.*\/to/!d' file
这给出:'bash:$:command not found'。 – Village 2012-03-13 01:37:38
'$'不是键入的,它表示shell提示符 – 2012-03-13 01:39:15