Results 1 to 5 of 5
I have this script:
Code:
#!/bin/bash
while [ $1 ] ; do
lines=$(wc -l $1 | awk '{print $1}')
if [ $lines -ge 10 ] ; then
echo " $1 ...
- 07-01-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Script modification
I have this script:
That checks if a file has more than 10 lines and if so prints its content else it prints that it has less than 10 lines.What I want is the script to ask which file to check(using echo probably) so that the terminal execution will be like thatCode:#!/bin/bash while [ $1 ] ; do lines=$(wc -l $1 | awk '{print $1}') if [ $lines -ge 10 ] ; then echo " $1 has $lines lines" cat $1 else echo " $1 has less than 10 lines" fi shift done
and notCode:./script
Thanks in advance for your advices.Code:./script file_name
- 07-01-2008 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
You had it earlier on in your other script

Check it out....
http://www.linuxforums.org/forum/lin...tml#post603212
- 07-01-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Well,I must be an idiot not to find the similarity.Thanks for yr advice.I have this script now:
It's working like a charm...Code:#!/bin/bash read -p "enter the name of the file: " NAME lines=$(wc -l $NAME | awk '{print $1}') if [ "$lines" -ge "10" ] ; then echo "$NAME has $lines lines" cat $NAME else echo "$NAME has less than 10 lines" fi
- 07-01-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
you can use
to get just the count. No need for extra awk.Code:wc -l < $FILE
Code:[ `wc -l < file` -gt 10 ] && echo "greater than 10" || echo "less than 10"
- 07-01-2008 #5Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Thanks.Quite interesting.I'll keep that in mind for future scripts.


Reply With Quote