1826333 Members
3601 Online
109692 Solutions
New Discussion

create a shell script

 
SOLVED
Go to solution
Christian Marquardt_1
Regular Advisor

create a shell script

hello,
I need to write a shell script which reads every line from a textfile an split each line in two strings.
that's the file:
dir1 pathtodirectory1
dir2 pathtodirectory2
dir3 pathtodirectory3

I need a script which reads every line, split the line an paste the first value in the variable "dirname" and the second value in the variable "dirpath".

Can anyone help me???

kind regards
Christian
5 REPLIES 5
Peter Godron
Honored Contributor
Solution

Re: create a shell script

Christian,

#!/usr/bin/sh
while read dirname dirpath
do
echo $dirname
echo $dirpath
done < textfile
Muthukumar_5
Honored Contributor

Re: create a shell script

Simply as,

while read dirname dirpath;
do

echo ${dirname}
echo ${dirpath}

done < textfile

--
Muthu
Easy to suggest when don't know about the problem!
Luk Vandenbussche
Honored Contributor

Re: create a shell script

dirname=`awk -F " " '{print $1}' < inputfile`
dirpath=`awk -F " " '{print $2}' < inputfile`
Christian Marquardt_1
Regular Advisor

Re: create a shell script

Thanks,
everything works fine.

regards
Christian
Muthukumar_5
Honored Contributor

Re: create a shell script

Luk,

You script will make a problem there. You can not keep track of all informations into one variable.

You can use array concept. But having restriction to use upto 1024 only.

--
Muthu
Easy to suggest when don't know about the problem!