Quote:
Originally Posted by max_il
have a list of all satellite channels in a file I want to get only child channels that belongs to specific child channel i=base channel1
original contect of the file: B base channel1 C child channel1 C child channel2
B base channel2 C child channel3
B base channel3 C child channel4
I want to get only: child channel1 child channel2
|
You want to remove all lines that have only one child channel.
From the remaining lines, you want to remove everything up to the first C, then also the second C, and consolidate the white space around the C's.
Correct?
The first task can be done by looking for files that contain exactly one C and delete them:
Code:
sed '/^[^C]*C[^C]*$/d'
We look at a string not containing a C, then C, then another string not containing a C. And ensure that this is the entire line, from beginning (^) to end ($).
Second task: Remove any string NOT containing a C, followed by C and a blank.
In a second pass, remove the remaining C.
It's possible to do this in one pass, see the sed manual
http://www.gnu.org/software/sed/manual/sed.html.
We combine that with the first task (can be done in a single sed command as well, but I think it's easier to understand with a pipeline):
Code:
sed '/^[^C]*C[^C]*$/d' | sed 's/^[^C]*C //' | sed 's/ C//'
(I will leave the testing, removing of typos and ironing out of wrinkles to you)