whats the standard out put for wc -l data.txt on Ubuntu
I just started using Ubuntu OS, the command "wc -l data.txt" printed out '"number of lines" data.txt'. I would expect to get just "number of line"...
|
Code:
carl@Wizard:~$ wc -l earth.txt From wc --help: Code:
The options below may be used to select which counts are printed, always in |
If you want to see just the number, pass the data to wc on stdin rather than having it open the file itself:
Code:
$ wc -l <data.txt |
@rknichols Thanks, worked like a charm.
Code:
carl@Wizard:~$ wc -l <earth.txt |
If you're new to redirects (<, <<, <<<, > etc) it should be noted that some respect should be given to the fact that they can be destructive if a typo is made. For instance
joe@debian:~$ wc -l <important_data.txt # correct usage provides desired line count 228 joe@debian:~$ wc -l >important_data.txt # command hangs ^C # until terminated joe@debian:~$ wc -l <important_data.txt # file has been blanked 0 joe@debian:~$ cat important_data.txt joe@debian:~$ # :( cat'ing the file and piping it through wc is a safe, non-destructive alternative; joe@debian:~$ cat important_data.txt | wc -l 228 |
Thanks joecam1673, good to remember.
|
My pleasure.
Of course the practice of cat'ing a file into a pipe will cost you a process so ultimately mastering redirects and keeping proper rw permissions for important files is best practice. I actually use Code:
if [[ -n $file ]] |
All times are GMT -5. The time now is 10:10 PM. |