Posted by Hans-Henry Jakobsen
#!/bin/bash # # Shell script utility to read a file line line version 2 # This is simpler version of readline script # This script also demonstrate how to process data file # line by line and then separate line in fields, so that # you can process it according to your need. # # You can call script as follows # ./readline2 ### Main script stars here ### # Store file name here FILE="/etc/passwd" # field seprator, default is :, you can use blank space or # other character, if you have more than one blak space in # input line then use awk utility and not the cut :) FS=":" while read line do # store field 1 F1=$(echo $line|cut -d$FS -f1) # store field 2 F2=$(echo $line|cut -d$FS -f6) # store field F3=$(echo $line|cut -d$FS -f7) echo "User \"$F1\" home directory is $F2 and login shell is $F3" done < $FILE
Tags: bash