|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
if [ -f "yourfile" ]
then (echo '1';echo '2'; cat "yourfile") | wc -l fi <bonnie.tangyn@gmail.com> ??????:1155738329.279293.323320@74g2000cwt.googleg roups.com... > Dear all > > How can I add the number of rows count by 2? Because I am required to > include header and trailer in the number of counts. For example, if the > wc -l is returned 5 records. I need to output 7 because of header and > trailer. > > The script I use as follow: > > for f in *.txt > do > mv -i "$f" "$f.bak" > { printf "filenumber %s\n" "$(date +%y%m%d)" > cat "$f.bak" > wc -l "$f.bak" | awk '{print $1}' > } >"$f" > done > |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
fengrui wrote:
> if [ -f "yourfile" ] > then > (echo '1';echo '2'; cat "yourfile") | wc -l > fi > > <bonnie.tangyn@gmail.com> > ??????:1155738329.279293.323320@74g2000cwt.googleg roups.com... >> Dear all >> >> How can I add the number of rows count by 2? Because I am required to >> include header and trailer in the number of counts. For example, if the >> wc -l is returned 5 records. I need to output 7 because of header and >> trailer. >> >> The script I use as follow: >> >> for f in *.txt >> do >> mv -i "$f" "$f.bak" >> { printf "filenumber %s\n" "$(date +%y%m%d)" >> cat "$f.bak" >> wc -l "$f.bak" | awk '{print $1}' >> } >"$f" >> done >> Try this (using ksh) Y=$(wc -l $f.bak | awk '{ print $1 } ) let x=$(($Y+2)) print $x Ref: man ksh search for "Arithmetic evaluation -- Mark |
|
![]() |
| Outils de la discussion | |
|
|