32

こんにちは、私は UNIX が初めてで、受信した csv ファイルから行数を取得する必要があります。次のコマンドを使用してカウントを取得しました。

wc -l filename.csv

1 レコードのファイルが含まれていると考えてください。最初に * が付いたファイルがいくつか取得され、それらのファイルに対して同じコマンドを発行すると、カウントが 0 になります。* はここで何かを意味し、ctrlm(CR) の代わりにNL そのファイルの行数を取得する方法。問題を解決するコマンドを教えてください。前もって感謝します。

4

4 に答える 4

65

次のクエリは、カウントを取得するのに役立ちます

cat FILE_NAME  | wc -l
于 2015-01-08T13:53:43.347 に答える
12

同じフォルダに複数の.csvファイルがある場合は、

cat *.csv | wc -l

csv現在のディレクトリ内のすべてのファイルの合計行数を取得します。したがって、 -c文字数と-mバイト数をカウントします (ASCII を使用する限り同じです)。wc次のようにして、ファイルの数をカウントするために使用することもできます。ls -l | wc -l

于 2018-10-12T20:20:36.870 に答える
7

wc -l mytextfile

または、行数のみを出力するには:

wc -l <​​ mytextfile

Usage: wc [OPTION]... [FILE]...
or:  wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified.  With no FILE, or when FILE is -,
read standard input.
  -c, --bytes            print the byte counts
  -m, --chars            print the character counts
  -l, --lines            print the newline counts
  --files0-from=F    read input from the files specified by
                       NUL-terminated names in file F;
                       If F is - then read names from standard input
  -L, --max-line-length  print the length of the longest line
  -w, --words            print the word counts
  --help     display this help and exit
  --version  output version information and exit
于 2016-11-08T23:39:20.193 に答える