2017-10-31 7 views
0

입력 파일의 단어 수를 계산 AWK 사용

Hello World . 2 . This is a text . 4 
Another line . 2 . Some more words . 3 

출력 컬럼 2, 4, 및 이들 워드 카운트 인 출력 요구 (탭 구분) 여러 열로

1 . Hello World . 51.4 . This is a text . 200 
2 . Another line . 16.4 . Some more words . 600 

(탭 구분)

나는

awk '{print $2, "\t", NF}' > output.tsv 
,691에 들어 왔

하지만 하나의 명령으로 여러 열에 대해이를 수행하는 방법을 모릅니다. 구조에 대한

답변

1

awk!

awk 'BEGIN {FS=OFS="\t"} 
      {print $2,split($2,x," +"),$4,split($4,x," +")}' file 

Hello World  2 This is a text 4 
Another line 2 Some more words 3