Saturday, February 22, 2014

Linux How to concatenate text files

cat file1 file2 filen > outputfile

or if you want to concatenate all text files in directory:
cat *.txt > outputfile
or you can use >> operator to append to file:
cat file1 >> file2

Linux How to count words and lines in a text file

If you want to count words in some text file you could use:
wc -w <file>
example for file 2600.txt (War and Peace from Leo Tolstoy) from Guttenberg Project :
wc -w 2600.txt
output:
566321 2600.txt
 If you want to count lines in some text file you could use:
wc -l <file>
the same file for example
wc -l 2600.txt
output:
65008 2600.txt

Full options list for wc command:

  • -c or --bytes byte counts
  • -m or --chars character counts
  • -l or --lines newline counts
  • -L or --max-line-length lenght of longest line
  • -w or --words word counts

 also:
  • --help
  • --version