Saturday, March 26, 2016

Internal Field Separator IFS

 IFS='|'; echo -e "cyberciti.biz|202.54.1.1|/home/httpd|ftpcbzuser\nnixcraft.com|202.54.1.2|/home/httpd|ftpnixuser" | while read -r domain ip webroot ftpusername; do echo "[$domain] [$ip], [$webroot"]; done
[cyberciti.biz] [202.54.1.1], [/home/httpd]
[nixcraft.com] [202.54.1.2], [/home/httpd]

>
[cyberciti.biz] [202.54.1.1], [/home/httpd]
[nixcraft.com] [202.54.1.2], [/home/httpd]


IFS='\'; echo -e "cyberciti.biz|202.54.1.1|/home/httpd|ftpcbzuser\nnixcraft.com|202.54.1.2|/home/httpd|ftpnixuser" | while read -r domain ip webroot ftpusername; do echo "[$domain] [$ip], [$webroot"]; done

>
[cyberciti.biz|202.54.1.1|/home/httpd|ftpcbzuser] [], []                                                                                                                 
[nixcraft.com|202.54.1.2|/home/httpd|ftpnixuser] [], []

No comments:

Blog Archive