[kwlug-disc] bash has mapfile... I had no idea
Khalid Baheyeldin
kb at 2bits.com
Tue Dec 10 07:47:57 EST 2024
On Tue, Dec 10, 2024 at 3:33 AM Ronald Barnes via kwlug-disc <
kwlug-disc at kwlug.org> wrote:
>
> Today I learned about bash's `mapfile` built-in function.
>
> Next time I want to read lines from a file to an array for processing,
> that will be choice of methods.
>
That is interesting ...
For decades, I have been processing files in shell scripts using an older,
and more verbose, method, which works in plain old sh ...
It is like this, assuming the file is, say, comma delimited :
while read LINE
do
FIELD2=`echo $LINE | awk -F, '{print $2}'`
FIELD7=`echo $LINE | awk -F, '{print $7}'`
...
# Do something with the fields
done < myfile.txt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20241210/66f4bcff/attachment-0001.htm>
More information about the kwlug-disc
mailing list