Filter unwanted lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter unwanted lines
# 8  
Old 10-09-2007
Quote:
Originally Posted by Raynon
Hi Vino,

Thanks for the explanation.
But what does the red dot *.*07$/ signify ?
. stands for any character. A .* would stand for any number of characters.
# 9  
Old 10-09-2007
Hi Vino,

That's some new and gd knowledge for me!!
Thanks alot for sharing ! Smilie
# 10  
Old 10-10-2007
Hi Vino,

If the file happens to be below (as the input) after using the sed earlier, i would want to cut out those with ABC in the first 3 characters of the 2nd field of those lines with "** ABCXX ZZZ VVV 07" pattern
as shown below and save as another filename. However the number of lines in between the ** pattern is random , fields of such patterm " bbb k= cccc" are random as well.
Can you help me ?

Input:

aaa k= aaaa
bbb k= cccc
ggg k= pppp
** XXXXX ZZZ VVV 07
mmm k= qqqq
eee k= yyyy
rrr k= vvvv
** ABCXX ZZZ VVV 07
mma k= qqqq
eer k= yyyy
rrq k= vvvv

** XXXXX ZZZ VVV 07
mgm k= qqqs
eae k= yyys
ppp k= vvvs
** ABCXX ZZZ VVV 07
mma k= qqqq
ear k= yyyy
raq k= vvvdv

** XXXXX ZZx VVx 07
mma k= qqqq
ear k= yyyy


Expected Ouput

** ABCXX ZZZ VVV 07
mma k= qqqq
eer k= yyyy
rrq k= vvvv
** ABCXX ZZZ VVV 07
mma k= qqqq
ear k= yyyy
raq k= vvvdv

Last edited by Raynon; 10-10-2007 at 09:35 PM..
# 11  
Old 10-11-2007
You should always experiment a little. That is the best learning.
This may help
Code:
sed -n -e "/k=/p" -e '/^\*\* ABC.*07$/p' inputfile > outfile

# 12  
Old 10-11-2007
Hi Vino,

Thanks for lending a hand.
But it seems that all the lines with "k=" are appended in which some are unwanted. Pls help me .
# 13  
Old 10-11-2007
Quote:
Originally Posted by Raynon
But it seems that all the lines with "k=" are appended in which some are unwanted. Pls help me .
Can you show your input, the output and the expected output ? I dont understand when you say 'k= are appended in which some are unwanted'.
# 14  
Old 10-11-2007
Hi Vino,

My output is below

Code:
$ sed -n -e "/k=/p" -e '/^\*\* ABC.*07$/p' input
aaa k= aaaa
bbb k= cccc
ggg k= pppp
mmm k= qqqq
eee k= yyyy
rrr k= vvvv 
** ABCXX ZZZ VVV 07
mma k= qqqq
eer k= yyyy
rrq k= vvvv 
mgm k= qqqs
eae k= yyys
ppp k= vvvs 
** ABCXX ZZZ VVV 07
mma k= qqqq
ear k= yyyy
raq k= vvvdv 
mma k= qqqq
ear k= yyyy
$

But what i need is

Code:
** ABCXX ZZZ VVV 07
mma k= qqqq
eer k= yyyy
rrq k= vvvv 
** ABCXX ZZZ VVV 07
mma k= qqqq
ear k= yyyy
raq k= vvvdv

In other words i only want those data in blue. Pls help me.

aaa k= aaaa
bbb k= cccc
ggg k= pppp
** XXXXX ZZZ VVV 07
mmm k= qqqq
eee k= yyyy
rrr k= vvvv
** ABCXX ZZZ VVV 07
mma k= qqqq
eer k= yyyy
rrq k= vvvv

** XXXXX ZZZ VVV 07
mgm k= qqqs
eae k= yyys
ppp k= vvvs
** ABCXX ZZZ VVV 07
mma k= qqqq
ear k= yyyy
raq k= vvvdv

** XXXXX ZZx VVx 07
mma k= qqqq
ear k= yyyy

Last edited by Raynon; 10-11-2007 at 06:56 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter ONLY lines with non-printing charaters

I have a file contains data with non-printing characters. i have used cat -v filename to display whole data with non-printing characters also. However, i need lines with non-printing characters into seperate file. My file is huge and looks like i have to manully find lines using cat -v filename |... (3 Replies)
Discussion started by: JSKOBS
3 Replies

2. Shell Programming and Scripting

awk prints unwanted new lines

Hello, I need a little help with the following: I'm using AWK to read input from a comma-seperated value file, and only printing certain fields like so: awk -F "," '{print $1,$3,$6}' /list.csv | tail -1 Which outputs the following: server1 APPID OS I run into a problem... (8 Replies)
Discussion started by: LinuxRacr
8 Replies

3. Shell Programming and Scripting

awk to filter multiple lines

Hi. I need to filter lines based upon matches in multiple tab-separated columns. For all matching occurrences in column 1, check the corresponding column 4. IF all column 4 entries are identical, discard all lines. If even one entry in column 4 is different, then keep all lines. How can I... (5 Replies)
Discussion started by: owwow14
5 Replies

4. UNIX for Dummies Questions & Answers

Filter lines common in two files

Thanks everyone. I got that problem solved. I require one more help here. (Yes, UNIX definitely seems to be fun and useful, and I WILL eventually learn it for myself. But I am now on a different project and don't really have time to go through all the basics. So, I will really appreciate some... (6 Replies)
Discussion started by: latsyrc
6 Replies

5. Shell Programming and Scripting

get rid of unwanted lines

Hi , My output contains the below contents When i execute df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' i get output as below tpshghghg.fgh.com:/vol/scmvol1/scm-vobstore/WebArch.vbs 1.7T 1.3T 452G 74% /vob/WebArch... (6 Replies)
Discussion started by: ptappeta
6 Replies

6. Shell Programming and Scripting

Filter a .kml file (xml) to remove unwanted entries

Ok, i have a .kml file that that i want to trim down and get rid of the rubbish from. its formatted like so: <Placemark> <name><!]></name> <description><!</b><br/>Frequency: <b>2437</b><br/>Timestamp: <b>1304892397000</b><br/>Date: <b>2011-05-08... (11 Replies)
Discussion started by: Phear46
11 Replies

7. Shell Programming and Scripting

How to filter only the last 'n' lines of a grep output?

I am running a grep query for searching a pattern, and the output is quite huge. I want only the last 200 lines to be displayed, and I am not sure if tail will do the trick (can tail read from std in/out instead of files?). Please help me out. (1 Reply)
Discussion started by: shell_newbie
1 Replies

8. Shell Programming and Scripting

grep out unwanted lines

Hi, I got a log file and I want to grep out a list of unwanted line which are IP's. Basiclly I want everything ecxept the ip's from my list. If I do a while read line do grep -v $ip_from_my_list logfile done <ip_list it just grep's one IP at a time and repeats. :( Thanks for... (3 Replies)
Discussion started by: stinkefisch
3 Replies

9. Shell Programming and Scripting

Remove unwanted lines

I have a .xml file, where i need some output. The xml file is like: Code: <?******?></ddddd><sssss>234</dfdffsdf><sdhjh>534</dfdfa>......... /Code I need the output like: code 234 534 . . . /code How can i do it? (5 Replies)
Discussion started by: anupdas
5 Replies

10. UNIX for Advanced & Expert Users

How to Remove the unwanted Blank Lines

I have a file with the below data, i would like to remove the end blank lines with no data. I used the below commands but could not able to succeed, could you please shed some light. Commands Used: sed '/^$/d' input.txt > output.txt grep -v '^$' input.txt > output.txt input.txt file... (5 Replies)
Discussion started by: Ariean
5 Replies
Login or Register to Ask a Question