[Urgent] Unix Help required

raksrules

Well-Known Member
Elite
Aug 30, 2007
9,859
1,726
378
Mumbai <--> Pune
In Unix i am using the following command to read one line from a file and echo it but this does not work. I have used it before (in another project) and it had worked there

Code:
cat /usr/tmp/abc.txt | read errcode
echo $errcode
Is there any other way i can read from this file which will have only one line.
 

kekerode

Active Member
Adept
Jul 29, 2009
568
7
32
Bangalore
try same on bash shell if not using it

i think another way will be

Code:
read errcode < cat /usr/tmp/abc.txt
echo $errcode
 

kekerode

Active Member
Adept
Jul 29, 2009
568
7
32
Bangalore
then may be this work out for you

Code:
errcode=`cat /usr/tmp/abc.txt`

echo $errcode
Code:
[kekerode@m-net ~]$ cat abc.txt

skjdajkdakjdasjkdas

[kekerode@m-net ~]$ echo $err123

[kekerode@m-net ~]$ err123=`cat abc.txt`

[kekerode@m-net ~]$ echo $err123

skjdajkdakjdasjkdas

[kekerode@m-net ~]$
 

nukeu666

Well-Known Member
Adept
Dec 19, 2006
2,156
45
112
36
try this...should work for file of any length

cat my.file | while read LINE ; do
<work>
done
 

raksrules

Well-Known Member
Elite
Aug 30, 2007
9,859
1,726
378
Mumbai &lt;--&gt; Pune
kekerode said:
then may be this work out for you

Code:
errcode=`cat /usr/tmp/abc.txt`
echo $errcode
Code:
[kekerode@m-net ~]$ cat abc.txt
skjdajkdakjdasjkdas
[kekerode@m-net ~]$ echo $err123

[kekerode@m-net ~]$ err123=`cat abc.txt`
[kekerode@m-net ~]$ echo $err123
skjdajkdakjdasjkdas
[kekerode@m-net ~]$
Yeah this one worked perfect. :hap2:

nukeu666 said:
try this...should work for file of any length

cat my.file | while read LINE ; do
<work>
done
I had tried this but it did not work.