unix - count of columns in file

前端 未结 11 1915
北海茫月
北海茫月 2020-12-22 19:17

Given a file with data like this (i.e. stores.dat file)

sid|storeNo|latitude|longitude
2|1|-28.03720000|153.42921670
9|2|-33.85090000|151.03274200

11条回答
  •  粉色の甜心
    2020-12-22 19:42

    select any row in the file (in the example below, it's the 2nd row) and count the number of columns, where the delimiter is a space:

    sed -n 2p text_file.dat | tr ' ' '\n' | wc -l
    

提交回复
热议问题