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!

which file is longer??

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
any ideas as to why this isn't working, please??

It is a script to determine which file is longer in line length.....

let j = &quot; $(wc -l <$ file)&quot;

if [ $1 -gt $2 ]
then
echo &quot;$1 is longer than $2&quot;
elif
[ $1 -eq $2 ]
then
echo &quot;$1 is the same length as $2&quot;
else
[ $1 -lt $2 ]
echo &quot;$2 is longerthan $1&quot;
fi
Thank you!!!
 
Hi ruby12,

first of all I don't understand the first line of your script (and it is syntactically wrong). What do you want to achieve with that?

A simple solution is the following script:

#!/bin/ksh

first_file=`wc -l $1`
LINES_FIRST_FILE=`echo $first_file | awk '{ print $1 }'`

second_file=`wc -l $2`
LINES_SECOND_FILE=`echo $second_file | awk '{ print $1 }'`

[[ $LINES_FIRST_FILE -gt $LINES_SECOND_FILE ]] && print &quot;$1 is longer than $2&quot;
[[ $LINES_FIRST_FILE -eq $LINES_SECOND_FILE ]] && print &quot;$1 is the same length as $2&quot;
[[ $LINES_FIRST_FILE -lt $LINES_SECOND_FILE ]] && print &quot;$1 is shorter than $2&quot;

exit 0

mrjazz [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top