![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rename a file to have Date and Line Count | bmkux | Shell Programming and Scripting | 2 | 03-10-2008 10:07 AM |
| Unix shll script for character count findings? | sethunath | Shell Programming and Scripting | 2 | 07-07-2007 09:26 AM |
| Want display a line with space in file by unix script | arunkumar_mca | UNIX for Dummies Questions & Answers | 9 | 05-21-2007 12:12 PM |
| grep and count no of occurences in every line of a file | srikanthgr1 | Shell Programming and Scripting | 12 | 04-20-2007 09:16 AM |
| Unix Script with line number at beginning of each line. | mascorro | Shell Programming and Scripting | 5 | 06-19-2006 04:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help On Unix Script Count Line Of File
I have to compare the number of files of two files on a Shell Script:
I tryied with wc and wiith sed but I can not make an integer... #!/bin/sh . . n = ls -l | wc -l $file1 `echo "Line: "$n". ">>$LOGFILE` xx = sed -n '$=' $file2 `echo "Line: "$xx". ">>$LOGFILE` Aways ERRORRRRR!!!!!!!!! Can enybody help me with this problem and explane to me how to use an output as an integer? TK's alot |
|
||||
|
Tk you but still error...
Thenk's a lot for the response, but it still give me a:
...../Send..sh: syntax error at line 167: `n=$' unexpected it looks like it doesn't like: n=$(ls -| | wc -l $file) any other suggestions, also because after I need to do some arithmethic operations with n, like: n=$n-9 tk's again |
|
|||||
|
That is because you are using sh and trying to use bash specific constructs. This should work with sh:
Code:
$ cat ./comp_val
#!/bin/sh
file1=names
file2=${file1}.tmp
LOGFILE=test.log
cp $file1 $file2
n=`ls -l | wc -l $file1 |awk '{print $1}'`
echo "In $file2: Line: ${n}." > $LOGFILE
xx=`sed -n '$=' $file2`
echo "In $file1: Line: ${xx}. ">> $LOGFILE
echo "$n-2="`expr ${n} - 2` >> $LOGFILE
cat $LOGFILE
$
$
$ ./comp_val
In names.tmp: Line: 8.
In names: Line: 8.
8-2=6
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|