Re: Howto read file line-by-line in bash
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Fri, 25 Apr 2008 18:26:08 +0200 (CEST)
2008-04-25, 08:03(-07), Guru:
[...]
Try using this..[...]
OLDIFS=$IFS
IFS="|"
for line in `cat test.data`;
do
echo $line;
done
IFS=$OLDIFS
This is simple and crisp.
And you oversaw three more problems: empty lines are discarded,
try it with a line containing "*", and if IFS was previously
unset, it becomes set to the empty string which has a totally
different meaning.
Using loops in shells always leads to this kind of corner case
problems. Shells are not meant to be used like that, avoid loops
to process text.
--
Stéphane
.
- References:
- Re: Howto read file line-by-line in bash
- From: Guru
- Re: Howto read file line-by-line in bash
- Prev by Date: Re: how to make a script of this one-liner...
- Next by Date: Re: how to test if a file is more than one hour old in ksh
- Previous by thread: Re: Howto read file line-by-line in bash
- Next by thread: how to make a script of this one-liner...
- Index(es):
Relevant Pages
|