General discussion

Locked

line count

By rgooding ·
e.g. wc -l filename
gives: 2000 filename

This gives the # of lines and also shows the filename.

I want to extract the # of lines only (2000) and not show the filename. I want to try to do this in one line and not have temporary lines.

Thanks

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Cactus Pete In reply to line count

You could pipe it to awk and remove just the one space delimited column you wanted...

wc -l filename |awk $1

That might do it, though I don't have a nix box at my fingertips right now

Collapse -

by Cactus Pete In reply to

Actually, that would be wrong [syntax is different], and there's something perhaps better:

cat filename | wc -l

That should do it.

Collapse -

by Gary_W In reply to line count

Take it a step further and get rid of leading blanks or tabs too by assigning the result to an integer variable. Using the korn shell, which supports this:

#!/usr/bin/ksh
integer linecount=`cat filename|wc -l`

Use $linecount to refer to the linecount in your script as:

echo $linecount

Gary

Collapse -

by rgooding In reply to line count

I already have a file with one line. The contents of the line looks like: 4000 filename.txt.

What I need is to get the "4000" from the line.

Hope this explains it further...Thanks agin

Collapse -

by Gary_W In reply to line count

Ok, here ya go:

# Cut field 1 where the delimiter is a space.
integer linecount=`cat filename|cut -f1 -d' '`

echo $linecount

Mote that there is a space between the single quotes.

Gary

Collapse -

by rgooding In reply to

GREAT!!!! That is exactly what I need. Thanks a lot.

Richard

Collapse -

by rgooding In reply to line count

This question was closed by the author

Back to Linux Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums