You can use the while loop and read command to read a text file line by line under KSH.
KSH read while loop syntax
#!/bin/kshIn this example, you are reading file separated by | fields. Sample domains.txt:
file="/path/to/file.txt"
# while loop
while read line
do
# display line or do somthing on $line
echo "$line"
done <"$file"
cyberciti.biz|74.86.48.99
nixcraft.com|75.126.168.152
theos.in|75.126.168.153
cricketnow.in|75.126.168.154
vivekgite.com|75.126.168.155
#!/bin/kshHowever, following is recommend syntax to set the Internal field separator (see discussion below):
# set the Internal Field Separator to a pipe symbol
IFS='|'
# file name
file=/tmp/domains.txt
# use while loop to read domain and ip
while read domain ip
do
print "$domain has address $ip"
done <"$file"
#!/bin/ksh
# file name
file=/tmp/domains.txt
# use while loop to read domain and ip
# set the Internal Field Separator to a pipe symbol
while IFS=\| read domain ip
do
print "$domain has address $ip"
done <"$file"
Suggested readings:
- ksh man page
No comments:
Post a Comment