LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 12-01-2015, 12:00 PM   #1
max_il
LQ Newbie
 
Registered: Dec 2015
Posts: 1

Rep: Reputation: Disabled
Cool printing first lines section ,until getting to the first space


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

I have tried: cat /tmp/channel_list |grep -E -A10 '(^| )'$i'( |$)'|grep -E -A10 '(^| )'$i'( |$)'|sed -n '/^B/,/^B/p' |grep -v B |perl -i -pe 's/\s+\n/\n/'|sed 's/^ *//; s/ *$//; /^$/d'

getting : C child channel1 C child channel2 C child channel3

Please let me know how to get only: child channel1 child channel2
 
Old 12-01-2015, 02:13 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Post the file
 
Old 12-01-2015, 05:51 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by max_il View Post
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)
 
Old 12-01-2015, 09:35 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
grep 'base channel1' t.t|awk '{print $5,$6,$8,$9}'
child channel1 child channel2
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Awk: Desire script to suppress section from keyA plus >=0 lines after with a "!" kent_unix Programming 2 07-18-2015 02:08 AM
[SOLVED] Printing next n lines using awk sras Linux - Kernel 1 07-08-2013 07:54 AM
[SOLVED] Printing all the lines Before the match pradeepdee6 Linux - Newbie 7 07-20-2012 01:03 PM
Printing to printable CDs: Bottom section won't print CJ Chitwood Linux - General 1 10-08-2007 11:29 PM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 02:03 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration