1753971 Members
7945 Online
108811 Solutions
New Discussion юеВ

Re: Shell script

 
SOLVED
Go to solution
PARK FOH CHIN
Occasional Contributor

Shell script

Hi,

I've 2 files :
1) 'main.txt' with the following 10 lines content :
one-one-one-one
two-two-two-two
three-three-three-three
four-four-four-four
five-five-five-five
six-six-six-six
seven-seven-seven-seven
eight-eight-eight-eight
nine-nine-nine-nine
ten-ten-ten-ten

2) 'sub.txt' whith the following 5 lines content :
1
3
5
7
9

I want to write a script to read the content from 'sub.txt', and
extract the n+1 (n is the number in sub.txt content)line from
'main.txt' file.
Therefore, the output extracted from 'main.txt' will be :
two-two-two-two
four-four-four-four
six-six-six-six
eight-eight-eight-eight
ten-ten-ten-ten

Pls advise.
Thanks & regards
Chin
11-Jun-09 @3:35pm
2 REPLIES 2
Suraj K Sankari
Honored Contributor
Solution

Re: Shell script

Hi,
see the below script

for i in `cat sub.txt`
do
sed -n `expr $i + 1`p main.txt
done


Suraj
PARK FOH CHIN
Occasional Contributor

Re: Shell script

Hi,
Excellent script - short, simple & powerful.
Thank you very much.

Best regards
Chin
11-Jun-09@6:05pm