-
How to read a file in UNIX
Still I need help.. :-((
Now scrit looks like
----------------------
#/bin/sh
filename='/opt/oracle/sameerd/sam/sam.txt'
for LINE in `cat $filename`
do
ID=`echo $LINE | cut -d'|' -f1`
FIRSTNAME=`echo $LINE | cut -d'|' -f2`
LASTNAME=`echo $LINE | cut -d'|' -f3`
echo "Id is " $ID
done
-----------------------
My line is
10 | J OHN | MILLER
20 | MARK | BRUNCE
And the output is...
----------------------
Id is 10
Id is
Id is J
Id is OHN
Id is
Id is MILLER
Id is 20
Id is
Id is MARK
Id is
Id is BRUNCE
----------------------
When I have said echo ONLY ID.. why the output is displaed for each element?
Thanks
Sameer
-
ok, instead of using :
for LINE in $(cat file)
do
...
use :
cat file | while read LINE
do
...
-
How to read a file in UNIX
Hey...
THANKS A LOT
I am sorry.. But I really asked YOU THOUSANDS of silly questions...
But I am very new to shell scripts..
Thanks once again
Sameer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|