Tag Info

New answers tagged


To append only the amount of lines, you can try this $ cat example.txt | wc -l >> example.txt This will only display the total amount of lines in the file


The following script adds the line count to the end of the file if it is not already there, but deletes and replaces it if there is already a line count. This allows you to run this script every time your file(s) are edited without adding multiple 'Line count:' lines. #! /bin/bash count=$(wc -l "$1" | cut -d' ' -f1) tail -1 "$1" | grep -q '^Line count: ' ...


As you know, wc -l by default, includes the result number plus the file name. If for some reason it is better to have literally just the result number only, try this: wc -l example.txt | cut -d' ' -f1 >> example.txt So if example.txt started with only 3 lines, eg: a b c After you run the above, use tail to look at the last lines (in this case ...


wc -l example.txt >> example.txt


You can pass the filename to the STDIN of wc to get only the number of lines : wc -l <filename.dat To save it as a variable : var="$(wc -l <filename.dat)" Example : $ wc -l foo.txt 12 foo.txt $ wc -l <foo.txt 12 $ var="$(wc -l <foo.txt)" $ echo "$var" 12 Note that as St├ęphane Chazelas has pointed out, some wc variants might add ...


# for each file in the current directory you can refine the ls command to match # only the files you want. or if in a script file pass in the file list for file in * do # if the file has more than 10 lines. if (( $(<"${file}" wc -l) > 10 )); then # print line 3 to end of file and pipe it to a file with the same # name as the ...


assuming no file with funny char in their name for file in * do line=$(wc -l < "$file' ) if [ $line -ge 10 ] then tail -n +3 <"$file" > "${file}.checked" fi done this basically count line in every file, then if over 10, print all lines, starting at the third.

Top 50 recent answers are included