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!

IFS=

Status
Not open for further replies.

tempest92

Technical User
Sep 16, 2003
110
GB
hi guys,

i want to read through a file line by line identifying records that match a pattern. i have found some code that does what i want -

grep TEXT /my/file |
while IFS= read -r LINE
do
echo $LINE
done

can someone just tell me what the 'IFS=' is actually doing ?

thanks !!
 
Hi,

IFS stands for Internal Field Separator.
In your case, IFS= means that no Internal Field Separator is defined, so command 'read' will read th whole line.

Code:
echo " a b,c d e f g" |
while IFS= read -r L1 L2 L3
do
echo L1=$L1
echo L2=$L2
echo L3=$L3
done

The same sample with IFS set to space will produce another output
Code:
echo " a b,c d e f g" |
while IFS=" " read -r L1 L2 L3
do
echo L1=$L1
echo L2=$L2
echo L3=$L3
done
 
thanks aau for the prompt response !! have a good day !
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top