I have two files:
One: /tmp/starting
has following content:
15
30
45
Two: /tmp/ending
has following content:
22
35
50
I want to read these files line by line simultaneously and use them in another command. For Example,
sed -n '15,22p' myFilePath
sed -n '30,35p' myFilePath
sed -n '45,50p' myFilePath
How Can I do this in Shell Script?
You can get the strings that you want from the paste
command:
$ paste -d, starting ending
15,22
30,35
45,50
You can use this with your sed
command as follows:
while read range
do
sed -n "${range}p" file
done < <(paste -d, starting ending)
The construct <(...)
is called process substitution. The space between the two <
is essential.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With