[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: This question is regarding shell , sorry for posting but in urgency



sjonnalagadda wrote:

hello all
I express my sincere applogies for posting this kind of stuff in rpm mailing list. But can any one help
I have a file like


abc
def
hig
from:
cdb
dfdfd
make dev
solution
from:
this is test
case from
i want to obtain all contentes from top to 2nd from:
can any onehelp in guiding me to write shell script
regards


############################
#!/bin/bash

file=$1
let fromcnt = 0

for i in `cat $file` ; do
if [ "$i" -eq "from:" ]; then
let fromcnt = $fromcnt + 1;
fi if [ "$fromcnt" -eq "2" ]; then
break;
fi
echo $i;
done
##############################


NOTE:
if [ "$fromcnt" -eq "2" ]; then ...

may be glitchy (maybe need an integer expression instead
of a string comparison) but I'm not sure.

you might not get the leading spaces on lines either:

abc
def
hig
from:
cdb
dfdfd
make dev
solution



HTH,
               -Tristan






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []