The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2008
fafo77 fafo77 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
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
  #2 (permalink)  
Old 02-08-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Couple minor tweaks to your code

[my file names does have eleven lines]


> cat comp_val
#! /bin/bash

file1=names
LOGFILE=test.log


n=$(ls -l | wc -l $file1)
echo "Line: "$n". ">>$LOGFILE

xx=$(sed -n "$=" $file1)
echo "Line: "$xx". ">>$LOGFILE



> rm *.log
> comp_val
> cat *.log
Line: 11 names.
Line: 11.
>
  #3 (permalink)  
Old 02-11-2008
fafo77 fafo77 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
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
  #4 (permalink)  
Old 02-11-2008
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
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
HTH
  #5 (permalink)  
Old 02-11-2008
fafo77 fafo77 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
Tku Very Much!!!

It works perfect!!!

Thank you very much, it help me a lot!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0