我有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