Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WC on Unix - Count Lines 1

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Good day ..

Using VI, I vi a file and while in it type the following command:

:1,2000 w newfilename <enter>

I then exit VI and ls -l. I then wc newfilename and get the following results:

2000 18360 418000 newfilename

What is the 2000 for that I selected above? I need to pick the first 2000 lines, the 2000 listed appears to be words.

What about the 18360 and 418000?

Help is appreciated.
 
This is the format of wc by default
<newlines>, <words>, <bytes>, <file>
so 2000=lines
18????=words
41????=bytes

If you want to transfer 1-2000 line form file1 to file2 then
#head -2000 file1 > file2

Patel
 
Thanks for the feedback ... another quick question.

Can you take the last 1000 lines? Take it from descending order instead of asc?
 
#!/usr/bin/ksh

MY_FILE=abc.xyz
COUNTER=0
NUM_LINES=`cat $MY_FILE|wc -l`
LINE_NUMBER=$NUM_LINES

until [ $LINE_NUMBER -eq 0 ]
do
LINE=`sed -n &quot;${LINE_NUMBER}p&quot; $MY_FILE`
echo $LINE
LINE_NUMBER=`expr $LINE_NUMBER - 1`
COUNTER=`expr $COUNTER + 1`
if [ $COUNTER -eq 2000 ]
then
exit
fi
done

Didn't have time to test this,
but I think it should work.
It should print up to the last 2000 lines backwards. Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
Hi
It is easy too.
#tail -1000 file1 > file2
#cat file2 |sort -r > file3

Patel
 
Hi,
I have run into issues with TAIL having a limited buffer and that even though I ask for the last 1000 lines, I only get the last 500 lines or so because it can only hold 4096 characters in its buffer.

Just something to be aware of when using Tail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top