1827295 Members
3096 Online
109717 Solutions
New Discussion

Sed in ksh

 
SOLVED
Go to solution
Vanquish
Occasional Advisor

Sed in ksh

Hi
I am using sed command to read from a XML file and write it out in another file the problem here is i have to read above and below the tags , if
some text exists otherwise exit
Thanks

STARTREL=`cat $FILE|sed -n '//='`
ENDREL=`cat $FILE|sed -n '/<\/Manifest>/='`
(( STARTREL = STARTREL - 1 ))
(( ENDREL = ENDREL + 1 ))
while
[ $STARTREL -le $ENDREL ]
do
RELNM=`cat $FILE|sed -n "$STARTREL,$STARTREL P"`
$RELNM >> $RELNOTES
do
9 REPLIES 9
Rodney Hills
Honored Contributor
Solution

Re: Sed in ksh

sed may not be the right tool. How about the following perl one liner-

perl -ne 'print unless /^
This will print all lines, except those between and

HTH

-- Rod Hills
There be dragons...
Sundar_7
Honored Contributor

Re: Sed in ksh


How about this ?

sed '//,/<\/Manifest>/d' input > output
Learn What to do ,How to do and more importantly When to do ?
Francisco J. Soler
Honored Contributor

Re: Sed in ksh

Hi,

With awk you can:

awk '//,/<\/Manifest>/ {flag=1}
{if (!flag) print ; flag=0} ' file_in > f_out

Frank.
Linux?. Yes, of course.
Wilfredo R. Castro
Occasional Advisor

Re: Sed in ksh


Hi,
Maybe you still use "sed" but put a "\" before the "/".
Willie Castro
KapilRaj
Honored Contributor

Re: Sed in ksh

In Korn Shell,

The best to use if there are such characters is ";",

i.e.

cat kapilraj |sed -e "s;BAD BOY;GOODBOY;g"

Regds,

Kaps
Nothing is impossible
Elmar P. Kolkman
Honored Contributor

Re: Sed in ksh

Your problem is the while loop, I guess.

STARTREL and ENDREL might both contain multiple entries. If not, you can replace the while with an if. You even should replace the test with something like:
[ "0$STARTREL" -le "0$ENDREL" ]

There are more problems in this script, btw. So I would recommend looking at the solutions given so far. perl and awk are languages that have this problem solved easily, for instance:
awk '//,/<\/Manifest>/ {print}' < $FILE


Every problem has at least one solution. Only some solutions are harder to find.
Vanquish
Occasional Advisor

Re: Sed in ksh

Hi
awk '//,/<\/Manifest>/'filein >file out works reverse
it copies what is in between the tags i want to copy what in not between the tags

Thanks
Francisco J. Soler
Honored Contributor

Re: Sed in ksh

Hi,

See my previus answer.

Frank.
Linux?. Yes, of course.
Vanquish
Occasional Advisor

Re: Sed in ksh

Hi
I used
perl -ne 'print unless /^it works, but it prints out not as orignal
format i want to print it in orignal format.
Thanks