How to get a chunk of a file? [message #229290] |
Fri, 06 April 2007 09:07 |
lalit.thawani
Messages: 11 Registered: April 2007
|
Junior Member |
|
|
Hi All. ! I am stuck in the following
suppose i have
$ cat file
hi. this is the line 1
this is line 2
START This is what
i want.This is what i want
this is what i want
END
scs;jdfsj
jsjdsjk;dk
And i need the output file content as
START This is what
i want.This is what i want
this is what i want
END
Thanks in advance
[Updated on: Fri, 06 April 2007 09:08] Report message to a moderator
|
|
|
|
|
|
Re: How to get a chunk of a file? [message #229455 is a reply to message #229331] |
Sun, 08 April 2007 05:06 |
lalit.thawani
Messages: 11 Registered: April 2007
|
Junior Member |
|
|
Thanks a ton.!
The sed command perfectly solves my purpose.!
I have also worked on an alternative solution.(a script).
The sed command is better offcourse.
*********************************************************
startstring=START #assign the variables
endstring=END #assign the variables
flag=1 #sets the flag on
cat file|while read line
do
if [ $flag -eq 1 ]; #checks for flag which will be ON initially
then
echo $line|grep $startstring
if [ $? -eq 0 ];
then
flag=0 #if got the start string we set the flag OFF
fi
else
echo $line|grep $endstring
if [ $? -eq 0 ];
then
flag=1 #and again ON if get the end string
else
echo $line
fi
fi
done
****************************************************************
Let me know your comments on the script if possible
Thanks again.!
|
|
|