LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-16-2013, 02:50 PM   #1
ABOYEWAK
LQ Newbie
 
Registered: Feb 2013
Location: Lagos, Nigeria
Posts: 4

Rep: Reputation: Disabled
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"...
 
Old 02-16-2013, 03:22 PM   #2
mjolnir
Member
 
Registered: Apr 2003
Posts: 824

Rep: Reputation: 106Reputation: 106
Code:
carl@Wizard:~$ wc -l earth.txt
9 earth.txt
Nine lines. Seems to work as expected.

From wc --help:

Code:
The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
  -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
 
Old 02-16-2013, 03:49 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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
25
$
 
1 members found this post helpful.
Old 02-16-2013, 04:30 PM   #4
mjolnir
Member
 
Registered: Apr 2003
Posts: 824

Rep: Reputation: 106Reputation: 106
@rknichols Thanks, worked like a charm.
Code:
carl@Wizard:~$ wc -l <earth.txt
9
 
Old 02-16-2013, 08:43 PM   #5
joecam1673
LQ Newbie
 
Registered: Aug 2009
Location: Chicago, IL
Distribution: Debian
Posts: 15

Rep: Reputation: 2
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
 
Old 02-18-2013, 06:53 AM   #6
mjolnir
Member
 
Registered: Apr 2003
Posts: 824

Rep: Reputation: 106Reputation: 106
Thanks joecam1673, good to remember.
 
Old 02-19-2013, 05:12 AM   #7
joecam1673
LQ Newbie
 
Registered: Aug 2009
Location: Chicago, IL
Distribution: Debian
Posts: 15

Rep: Reputation: 2
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 ]]
then
 >$file
fi
relativelty often to scrub temp files
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 11:43 AM
an other BASH question. trying to put a '- ' at the front of all lines in a txt file lleb Linux - Newbie 11 07-16-2012 08:08 PM
Need to convert a large number of file types from none standard to txt metalme Linux - Newbie 2 09-28-2009 05:46 PM
Whats a free sw to put capchas on a website? resetreset Linux - Server 1 07-28-2008 04:17 AM
what is the standard place to put sourcefiles and where install? ldp Debian 5 05-14-2004 10:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration