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!

trying to replace a line with two lines

Status
Not open for further replies.

msen

IS-IT--Management
Apr 24, 2001
36
US
This is not working



#!/usr/bin/ksh
2 export LOGFILE=/data/ndm/tmpproc/tmp.log
3 export PROCNUM=`ls -l *.ndm|wc -l`
4 echo $PROCNUM
5 ##print $AWKINFO
6 for file in `ls *.ndm`
7 do
8 cp $file $file.tmp
9 export LISTCAT=`(cat /data/ndm/tmpproc/$file|grep "echo 'x' ")` >> $LOGFILE
10 echo $LISTCAT
11 export SEDLIST='sysopts="sendmsg.ksh &LOCALFILE TESTNDM chase"' >> $LOGFILE
12 echo $SEDLIST
13 ##sed 's#&quot;sysopts=&quot;echo 'x' | mailx -s#sysopts=&quot;sendmsg.ksh &LOCALFILE TESTNDM chase&quot;#g' < $file.tmp > $file
14 ##sed -e s/&quot;$CR&quot;/'<!-- hate windows -->'/
15 ##sed -e s/&quot;$LISTCAT&quot;/'$SEDLIST'/ >> $LOGFILE
16 if [ -z $LISTCAT ] then
17 echo &quot;No entry&quot;
18 else
19 sed -e s/&quot;$LISTCAT&quot;/&quot;$SEDLIST&quot;/ >> $LOGFILE
20 fi
21 done
 
thanks for sharing!
What seems to be the problem?
How far have you gotten debugging the problem?

One potential issue:

if [ -z $LISTCAT ] then

should be

if [ -z $LISTCAT ]; then

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 

Some remarks :

- Correct if syntax (see vgersh99 post).
- The input file is missing for your sed command.
sed -e s/&quot;$LISTCAT&quot;/&quot;$SEDLIST&quot;/ $file >> $LOGFILE
- If there is more than one line containing &quot;echo 'x'&quot; in your input file,
the sed command will failed with a syntax error.

- Remove unnecessary export commands
- Instead of : cat file | grep xxx
do : grep xxx file
- The redirection in assignment statement do nothing, can be removed.
If you want a trace in $LOGILE, instead of : var=`command ` >> $LOFILE
do : var=`command | tee -a $LOGFILE`
- put the SEDLIST assignment outside the for loop


Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top