1832240 Members
2609 Online
110041 Solutions
New Discussion

wc

 
SOLVED
Go to solution
Prabhu_7
Frequent Advisor

wc

wc -l filename.txt

gives me ,
8 filename.txt

i want it to return only 8.
i want to check no of lines of one file with other one.

like ,
If wc -l f1.txt > wc -l f2.txt






9 REPLIES 9
PIYUSH D. PATEL
Honored Contributor

Re: wc

wc -l filename.txt | awk '{print $1}'

HTH,
Piyush
Mark Greene_1
Honored Contributor
Solution

Re: wc

try this:

if [ `cat f1.txt|wc -l` -gt `cat f2.txt|wc -l` ]; then

do stuff for greater than condition here

else

do stuff for not greater than condition here

fi

Note that I used the grave (backquotes) in the if statement.

HTH
mark
the future will be a lot like now, only later
Jeff Schussele
Honored Contributor

Re: wc

Hi Prabhu,

Try this:

wc -l filename.txt | awk '{ print $1}'

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Helen French
Honored Contributor

Re: wc

Try this:

# wc -l vg00.map |awk '{print$1}'
Life is a promise, fulfill it!
PIYUSH D. PATEL
Honored Contributor

Re: wc

wc -l f1.txt | awk '{print $1}' > wc -l f2.txt | awk '{print $1}'

Sorry for the second post....

HTH,
Piyush
Dario_1
Trusted Contributor

Re: wc

Hi!!

How about:

cat filename.txt | wc -l

Regards,

DR
Helen French
Honored Contributor

Re: wc

Oops .. replace vg00.map with your file_name. I just copied the command which I tried =))
Life is a promise, fulfill it!
James R. Ferguson
Acclaimed Contributor

Re: wc

Hi:

You could do:

# X=`wc -l f1.txt|cut -d" " -f1`

# Y=`wc -l f2.txt|cut -d" " -f1`

# if [ "${X}" -gt "${Y}" ]; then
...

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: wc

Hi (again):

Of course, if you prefer:

# [ `wc -l f1.txt|cut -d" " -f1` -gt `wc -l f2.txt|cut -d" " -f1` ] && echo "f1 has more lines than f2"

Regards!

...JRF...