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!

work on each line returned by GREP

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH

Hi,

I need to do something like

for i `ls -1 *.sql `
do
for k in `grep "MY TEXT" $j `
do
..
...
..
done

done


And one of the sql files may contain lines like

MY TEXT ABC
fkjgnhdfg
MY TEXT PQR
dfkljgn
MY TEXT XYZ

So a grep would return three lines and I want to work on the three lines separately, but with the command syntax I have in my script each line comes out as three lines because of the space in the three words.

Is there a way to make grep return one line and not three in the k-shell script.

Many Thanks,
 
How about something like

Code:
...
   grep "MY TEXT" $j | while read k;
   do
      #work with $k
   done
...
 
If you mean that 'MY TEXT ABC' is seen as three separate variables try
Code:
IFS='
'
This sets the input record separator to newline (the default is space) so that each line is seen as a separate record.

Ceci n'est pas une signature
Columb Healy
 
Hi

Just to make the smart @$$. ;-)
Columb said:
This sets the input record separator to newline (the default is space)
Includes space, but not only space.
man ksh said:
IFS
Internal field separators, normally space, tab, and new-line that are used to separate command words [gray](...)[/gray]

Feherke.
 
I used the solution posted by MoreFeo and it worked the trick. Will try the others later on...

Thanks for the suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top