Bu Blogda Ara

23 Eylül 2012 Pazar

while IFS='|' read -r

I really fancy the performance achieved while reading a stream line by line using file separator IFS and read -r option. For example assume you have a phone list like the below:

NAME SURNAME PHONE
john|smith|+44.............
ali|veli|+90..........

...

carlos|suarez|+34..............

You can process the file with the below script line by line having name surname and phone numbers separated.

cat phonelist | while IFS="|" read -r V1 V2 V3; do echo "Name:$V1 Surname:$V2 Phone:$V3";done

Its really fast compared to reading line by line and using awk for processing the lines.

Hiç yorum yok:

Yorum Gönder