IFS ( internal field separator) The shell uses the value stored in IFS, which is the space, tab, and newline characters by default, to delimit words for the read and set commands, when parsing output from command substitution, and when performing variable substitution.
IFS can be redefined to parse one or more lines of data whose fields are not delimited by the default white-space characters.
Here commands are executed from left to right.
thank u very much for the reply. Now i was trying to modify the record. I can access the specific field to modify according to ur told method but how can i write again the modified value into the file at that position from where i got?
thank once again.
Its available in code posted by anbu23,
modify the above to,
grep -i "saira" file | while IFS="|" read name no cntry
do
echo $name $modified_no $cntry
done > newfile
Or (if the matched patterns are unique):
{ IFS="|" read a b c;echo "$a $b"; }< <(grep Saira Addressbook)
And if your shell does not support process substitution:
grep Saira Addressbook|{ IFS="|" read a b c;echo "$a $b"; }
Corrected.
while IFS="|" read name no cntry
do
if [[ ${name% *} = "Saira" ]]; then
echo ${name}"|${modified_no}|"${cntry}
else
echo ${name}"|${no}|"${cntry}
fi
done < file > tmp
mv tmp file