read a file and assign value to variables from the content
read a file and assign value to variables from the content
am 26.09.2007 17:40:46 von rohitsagar
Hi
I have a file in unix named a.lst
the contents of file are (5 words seperated by a space)
-> cat a.lst
first second third fourth fifth
->
Now I want to declare five variables in a shell script and I want to
have this
a=first
b=second
c=third
d=fourth
e=fifth
Re: read a file and assign value to variables from the content
am 26.09.2007 17:46:43 von Joachim Schmitz
schrieb im Newsbeitrag
news:1190821246.291715.81600@k79g2000hse.googlegroups.com...
> Hi
>
> I have a file in unix named a.lst
> the contents of file are (5 words seperated by a space)
>
> -> cat a.lst
> first second third fourth fifth
> ->
>
>
> Now I want to declare five variables in a shell script and I want to
> have this
>
> a=first
> b=second
> c=third
> d=fourth
> e=fifth
read a b c d e
Bye, Jojo
Re: read a file and assign value to variables from the content
am 26.09.2007 18:48:49 von rohitsagar
On Sep 26, 10:46 am, "Joachim Schmitz"
digital.de> wrote:
> schrieb im Newsbeitragnews:1190821246.291715.81600@k79g2000hse.googlegr oups.com...
>
>
>
> > Hi
>
> > I have a file in unix named a.lst
> > the contents of file are (5 words seperated by a space)
>
> > -> cat a.lst
> > first second third fourth fifth
> > ->
>
> > Now I want to declare five variables in a shell script and I want to
> > have this
>
> > a=first
> > b=second
> > c=third
> > d=fourth
> > e=fifth
>
> read a b c d e
>
> Bye, Jojo- Hide quoted text -
>
> - Show quoted text -
Thanks a lot for reply.
I have another problem now.
I have a file with multiple lines
-> cat a.lst
first second third fourth fifth
sixth seventh eigth ninth tenth
->
Now I want to call the variables in a loop to get
a=first
b=second
c=third
d=fourth
e=fifth
then in second loop I want
a=sixth
b=seventh
c=eigth
d=ninth
e=tenth
:(
please help
Re: read a file and assign value to variables from the content
am 26.09.2007 18:55:47 von Joachim Schmitz
schrieb im Newsbeitrag
news:1190825329.939614.126340@57g2000hsv.googlegroups.com...
> On Sep 26, 10:46 am, "Joachim Schmitz"
> digital.de> wrote:
>> schrieb im
>> Newsbeitragnews:1190821246.291715.81600@k79g2000hse.googlegr oups.com...
>>
>>
>>
>> > Hi
>>
>> > I have a file in unix named a.lst
>> > the contents of file are (5 words seperated by a space)
>>
>> > -> cat a.lst
>> > first second third fourth fifth
>> > ->
>>
>> > Now I want to declare five variables in a shell script and I want to
>> > have this
>>
>> > a=first
>> > b=second
>> > c=third
>> > d=fourth
>> > e=fifth
>>
>> read a b c d e
>>
>> Bye, Jojo- Hide quoted text -
>>
>> - Show quoted text -
>
>
>
> Thanks a lot for reply.
> I have another problem now.
>
> I have a file with multiple lines
>
> -> cat a.lst
> first second third fourth fifth
> sixth seventh eigth ninth tenth
> ->
>
> Now I want to call the variables in a loop to get
>
> a=first
> b=second
> c=third
> d=fourth
> e=fifth
>
>
> then in second loop I want
> a=sixth
> b=seventh
> c=eigth
> d=ninth
> e=tenth
>
> :(
>
>
> please help
while read a b c d e < a.lst
do
echo $a $b $c $d $e
done
Re: read a file and assign value to variables from the content
am 26.09.2007 19:15:47 von rohitsagar
On Sep 26, 11:55 am, "Joachim Schmitz"
digital.de> wrote:
> schrieb im Newsbeitragnews:1190825329.939614.126340@57g2000hsv.googlegr oups.com...
>
>
>
> > On Sep 26, 10:46 am, "Joachim Schmitz"
> > digital.de> wrote:
> >> schrieb im
> >> Newsbeitragnews:1190821246.291715.81600@k79g2000hse.googlegr oups.com...
>
> >> > Hi
>
> >> > I have a file in unix named a.lst
> >> > the contents of file are (5 words seperated by a space)
>
> >> > -> cat a.lst
> >> > first second third fourth fifth
> >> > ->
>
> >> > Now I want to declare five variables in a shell script and I want to
> >> > have this
>
> >> > a=first
> >> > b=second
> >> > c=third
> >> > d=fourth
> >> > e=fifth
>
> >> read a b c d e
>
> >> Bye, Jojo- Hide quoted text -
>
> >> - Show quoted text -
>
> > Thanks a lot for reply.
> > I have another problem now.
>
> > I have a file with multiple lines
>
> > -> cat a.lst
> > first second third fourth fifth
> > sixth seventh eigth ninth tenth
> > ->
>
> > Now I want to call the variables in a loop to get
>
> > a=first
> > b=second
> > c=third
> > d=fourth
> > e=fifth
>
> > then in second loop I want
> > a=sixth
> > b=seventh
> > c=eigth
> > d=ninth
> > e=tenth
>
> > :(
>
> > please help
>
> while read a b c d e < a.lst
> do
> echo $a $b $c $d $e
> done- Hide quoted text -
>
> - Show quoted text -
This goes to infinite loop
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
first second third fourth fifth
Re: read a file and assign value to variables from the content
am 26.09.2007 19:54:55 von Cyrus Kriticos
rohitsagar@yahoo.com wrote:
> Joachim Schmitz wrote:
>> rohitsagar@yahoo.com schrieb
>>
>> while read a b c d e < a.lst
>> do
>> echo $a $b $c $d $e
>> done- Hide quoted text -
>
> This goes to infinite loop
while read a b c d e
do
echo $a $b $c $d $e
done < a.lst
--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Re: read a file and assign value to variables from the content
am 26.09.2007 19:56:40 von Joachim Schmitz
schrieb im Newsbeitrag
news:1190826947.806792.167600@22g2000hsm.googlegroups.com...
> On Sep 26, 11:55 am, "Joachim Schmitz"
> digital.de> wrote:
>> schrieb im
>> Newsbeitragnews:1190825329.939614.126340@57g2000hsv.googlegr oups.com...
>>
>>
>>
>> > On Sep 26, 10:46 am, "Joachim Schmitz"
>> > digital.de> wrote:
>> >> schrieb im
>> >> Newsbeitragnews:1190821246.291715.81600@k79g2000hse.googlegr oups.com...
>>
>> >> > Hi
>>
>> >> > I have a file in unix named a.lst
>> >> > the contents of file are (5 words seperated by a space)
>>
>> >> > -> cat a.lst
>> >> > first second third fourth fifth
>> >> > ->
>>
>> >> > Now I want to declare five variables in a shell script and I want to
>> >> > have this
>>
>> >> > a=first
>> >> > b=second
>> >> > c=third
>> >> > d=fourth
>> >> > e=fifth
>>
>> >> read a b c d e
>>
>> >> Bye, Jojo- Hide quoted text -
>>
>> >> - Show quoted text -
>>
>> > Thanks a lot for reply.
>> > I have another problem now.
>>
>> > I have a file with multiple lines
>>
>> > -> cat a.lst
>> > first second third fourth fifth
>> > sixth seventh eigth ninth tenth
>> > ->
>>
>> > Now I want to call the variables in a loop to get
>>
>> > a=first
>> > b=second
>> > c=third
>> > d=fourth
>> > e=fifth
>>
>> > then in second loop I want
>> > a=sixth
>> > b=seventh
>> > c=eigth
>> > d=ninth
>> > e=tenth
>>
>> > :(
>>
>> > please help
>>
>> while read a b c d e < a.lst
>> do
>> echo $a $b $c $d $e
>> done- Hide quoted text -
>>
>> - Show quoted text -
>
>
>
> This goes to infinite loop
>
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
> first second third fourth fifth
Oops,I've tried to avoid cat, apparently without luck...
try this:
cat a.lst|while read a b c d e
do
echo $a $b $c $d $e
done
Bye, Jojo
Re: read a file and assign value to variables from the content
am 26.09.2007 20:15:19 von Joachim Schmitz
"Cyrus Kriticos" schrieb im Newsbeitrag
news:5lvkleFanr46U1@mid.individual.net...
> rohitsagar@yahoo.com wrote:
>> Joachim Schmitz wrote:
>>> rohitsagar@yahoo.com schrieb
>>>
>>> while read a b c d e < a.lst
>>> do
>>> echo $a $b $c $d $e
>>> done- Hide quoted text -
>>
>> This goes to infinite loop
>
> while read a b c d e
> do
> echo $a $b $c $d $e
> done < a.lst
Ah, yes, that's what I intended, thanks...
Bye, Jojo
Re: read a file and assign value to variables from the content
am 26.09.2007 23:23:52 von Dummy
rohitsagar@yahoo.com wrote:
>
> Thanks a lot for reply.
> I have another problem now.
>
> I have a file with multiple lines
>
> -> cat a.lst
> first second third fourth fifth
> sixth seventh eigth ninth tenth
> ->
>
> Now I want to call the variables in a loop to get
>
> a=first
> b=second
> c=third
> d=fourth
> e=fifth
>
> then in second loop I want
> a=sixth
> b=seventh
> c=eigth
> d=ninth
> e=tenth
$ echo "first second third fourth fifth
sixth seventh eigth ninth tenth
" | perl -lane'$x = "a"; print $x++, "=$_" for @F'
a=first
b=second
c=third
d=fourth
e=fifth
a=sixth
b=seventh
c=eigth
d=ninth
e=tenth
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Re: read a file and assign value to variables from the content
am 03.10.2007 22:06:41 von rohitsagar
Thanks to all.