Operating System - HP-UX
1753797 Members
7011 Online
108799 Solutions
New Discussion юеВ

Need help in reading text file

 
SOLVED
Go to solution
Andres_13
Respected Contributor

Need help in reading text file

Hi all,

Consider a text file with the following format:

/filesystem1
/filesystem2
/filesystem3
/filesystem4
/filesystem5

Given the above file I'd need a shell script which read each line of the file, applies some format to every single line and then attach it to another file, somethingo like this:

FILESYSTEM "/filesystem1" server_hostname:"/filesystem1"
{
}

FILESYSTEM "/filesystem2" server_hostname:"/filesystem2"
{
}

FILESYSTEM "/filesystem3" server_hostname:"/filesystem3"
{
}

FILESYSTEM "/filesystem4" server_hostname:"/filesystem4"
{
}

FILESYSTEM "/filesystem5" server_hostname:"/filesystem5"
{
}

Each one of the above output must be added at the end of another text file.

I will really appreciate your support.
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need help in reading text file

Hi:

# cat ./mycomposer
#!/usr/bin/sh
while read LINE
do
echo "FILESYSTEM \"${LINE}\" server_hostname:\"${LINE}\""
echo "{\n}"
done < myfile

...where 'myfile' looks like:

# cat ./myfile
/filesystem1
/filesystem2
/filesystem3
/filesystem4
/filesystem5

Regards!

...JRF...
Andres_13
Respected Contributor

Re: Need help in reading text file

Thank you for your support James!!!

It worked just fine.