[英]Manipulate(exclude lines) a specific column of a .csv file, using UNIX/Linux
[英]Counting characters for specific column across all lines in Linux/unix
如何計算 tsv 文件中特定列的字符數,而此列包含句子而不是單個字符串? (我想計算列中的每一行)。
例如:(在 csv 的情況下)計算第二個字段/列的字符數:
輸入:
ab, an apple
ac, not juice
ad, I like
輸出:
ab, an apple , 7
ac, not juice, 8
ad, I like, 5
這對你有用嗎?
awk -F, '{printf "%s,%s,%s\n",$1,$2,length(gensub(/ /, "", "g", $2))}' sleiman.txt
我將文件命名為sleiman.txt
。 awk 的作用是:
,
作為輸入字段分隔符所以輸出是:
awk -F, '{printf "%s,%s,%s\n",$1,$2,length(gensub(/ /, "", "g", $2))}' sleiman.txt
ab, an apple ,7
ac, not juice ,8
ad, I like ,5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.