Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
- I need to read and ignore a file till i find a certain string and then write out the rest of the file in to another file using sh ... can some one help ? thanks
i tried using cat and a for loop but that breaks up the lines into words ... and the echo -n option does not work with my sh ... so it puts the words in seperate lines .
I also tried using cut - but that cuts all lines and not line by line .
Would be grateful for Any help would :).
The file is an XML file and i need to ignore text till the first line - but in fact a xml file could have a comment on the top - between which are optional then read and ignore the first true tag between < and >
i would like a script that can read a file line by line and the sample code to extract ( get sub strings of this line char by char ) i know the logic of id then fi ... thanks
this is for production - wish i could do it wothperl or java but for some crazy reason that the unix box admin only knows it ahs to be in sh

also please let the var of the in file name be InFIle
the new file be outFile , let the line that is currently read be currLine, and the logic to search in this line be shown - i searched the other posts that show how to read a file line by line but could not figure out where they are specifying the in file - not using $0 ... $1 .

Based on what I think you said, I would use awk (which is a component of sh).
If you could be more clear about what you want to eliminate from the file, someone may help with a script - such as eliminate all lines beginning with a line that contains "whatever" through and including a line that contains "whatever". And are we keeping or discarding only whole lines, or is there partial line work involved?
And an example of your data always helps.

picky,picky- "awk (which is a component of sh)". to me,"component" implies built-in.
awk is one of the numerous *nix utilities which
can be invoked from shells such as sh,rsh,ksh, bash ....is this a homework assignment which requires a "pure
shell" solution?

Please try something like this:#!/bin/ksh
FILE1="testfile"
FFLAG=0while read -r TESTDATA
do
if (( $FFLAG == 0 ))
then
if ((` echo $TESTDATA | grep -c "KEY:0"` ))
then
FFLAG=1
TESTDATA=`echo $TESTDATA | sed -e 's/^.*KEY:0/KEY:0/g'`
echo $TESTDATA
fi
else
echo $TESTDATA
fi
done < $FILE1Assuming the file you are trying to filter is 'testfile' and the pattern you are looking for is 'KEY:0'

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |