Browse - Programming Tips - Can I parse a file without awk (or other external program)?

Date: 2013oct27
Language: Bash
OS: Linux

Q.  Can I parse a file without awk (or other external program)?

A.  Sure, bash is very powerful.  One way is to set the IFS
(Inter Field Separator).  Its normally whitespace characters.
Its good to set it back when you are done.  Here's an example:

#!/bin/sh OLD_IFS=$IFS IFS=: cat /etc/passwd | while read LINE; do set - $LINE username=$1 password=$2 userid=$3 groupid=$4 humanname=$5 home=$6 shell=$7 done IFS=$OLD_IFS