[Urgent] Unix Help required

raksrules

Elite
Aug 30, 2007
11,173
3,427
453
Mumbai
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

Adept
Jul 29, 2009
581
11
82
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

Adept
Jul 29, 2009
581
11
82
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 ~]$
 

raksrules

Elite
Aug 30, 2007
11,173
3,427
453
Mumbai
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.