awk : deleting specific incorrect lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk : deleting specific incorrect lines
# 1  
Old 01-10-2011
awk : deleting specific incorrect lines

Hello friends,
I searched in forums for similar threads but what I want is to have a single awk code to perform followings;

I have a big log file going like this;
Code:
...
7450494 1724465 -47 003A98B710C0   
7450492 1724461 -69 003A98B710C0   
7450488 1724459 001DA1915B70 trafo_14:3   
7450482 1724458 -72 001DA1915B70   
7449713 1724464 000000000000 0  
7450469 1724464 0 003A98B6EC60 
...

Here I would like to delete lines which have their third field as 0. In addition, I would like to delete lines those have their 3rd field as '001DA1915B70' or '000000000000' as in 3rd and 5th line.

So the output would look like as follows;
Code:
7450494 1724465 -47 003A98B710C0   
7450492 1724461 -69 003A98B710C0      
7450482 1724458 -72 001DA1915B70

Any help is much appreciated.

Thank you very much,

Last edited by Franklin52; 01-10-2011 at 04:28 PM.. Reason: Correcting code tags
# 2  
Old 01-10-2011
Code:
awk ' ($3==0 || $3=="001DA1915B70" || $3=="000000000000" ) {next} {print}'  infile

This can be shortened to:
Code:
awk ' ($3==0 || $3=="001DA1915B70" ) {next} {print}'  infile

# 3  
Old 01-10-2011
Thanks a million Jim, this is helpful but I forgot to indicated that I do not only have '001DA1915B70' or '000000000000'. There are many more others also like '001100220000'.... Their common characteristic is to have a length longer than 2. How can I check for third field and decide if its length is bigger than 2, then i will delete that specific line. Therefore it will work for all others.

Thank you
# 4  
Old 01-10-2011
Something like this?
Code:
awk '$3 && int($3)==$3 && $3<100' file

This User Gave Thanks to Franklin52 For This Post:
# 5  
Old 01-10-2011
worked like a charm and I understand, thank you very much Franklin.
# 6  
Old 01-10-2011
Code:
awk '$3!~/^0/' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi editor deleting lines with specific pattern

Hi, I need to delete all lines in the file using vi editor which start with word aternqaco. Please assist. aternqaco.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment aternqa.__oracle_base='/amdbqa01/app/oracle'#ORACLE_BASE set from environment... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

2. Shell Programming and Scripting

Help required deleting specific lines from file

Hi, I have a file with 20 columns of data and hundreds of lines of the same format. Here is an example line. The data repeats underneath with the same format. 15 1 4 GLY - 1 65 LYSH 23 N - 24 H - 634 O 0.188 157.552 487 48.70I have been sorting this data by hand but I was wondering if I... (3 Replies)
Discussion started by: livbaddeley
3 Replies

3. Shell Programming and Scripting

Deleting specific lines in a file

Hello, I have a file filled with dates, such as: 04-08-2011 message 04-08-2011 message 03-08-2011 message 01-08-2011 message 31-07-2011 message 24-07-2011 message 15-07-2011 message 13-12-2008 message 26-11-2007 message And I want to delete those lines whose date is older than 10... (5 Replies)
Discussion started by: asanchez
5 Replies

4. Shell Programming and Scripting

deleting specific lines in a file

Hello, I have a file like: 26-07-2011 sunz02 message1 26-07-2011 sunz02 message2 26-07-2011 sunz02 message3 15-07-2011 sunz02 message1 15-07-2011 sunz02 message2 15-07-2011 sunz02 message3... (5 Replies)
Discussion started by: asanchez
5 Replies

5. Shell Programming and Scripting

Deleting specific lines in a file

Hello, I have a file like this one: 03-07-2011 sunz02 message1 03-07-2011 sunz02 message2 03-07-2011 sunz02 message3 01-07-2011 sunz02 message1 01-07-2011 sunz02 message2 01-07-2011 sunz02 ... (1 Reply)
Discussion started by: asanchez
1 Replies

6. Shell Programming and Scripting

deleting specific lines in a file

I want to delete all lines from a file (orig_file) that contain the regex values (bad_inv_list) I tried a for each loop with sed but it isn't working for file in `cat bad_inv_list`; do sed '/$file/d' orig_file > pared_down_file.1 mv pared_down_file.1 orig_file done I've added... (2 Replies)
Discussion started by: verge
2 Replies

7. Shell Programming and Scripting

Shell deleting specific lines

Hi, I'am working under unix solaris I have a text file with set of lines, each set of lines (BLOCK) have three fixed lines : Between SECND line and THEND we have N lines, N differ from a block to another sample : i have to make a script wich delete each 3 fixed lines if N=0... (3 Replies)
Discussion started by: salbanito
3 Replies

8. Shell Programming and Scripting

Merge lines in a file with Awk - incorrect output

Hi, I would like: FastEthernet0/0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 output errors, 0 collisions, 0 interface resets Serial1/0:0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort 0... (14 Replies)
Discussion started by: mv652
14 Replies

9. UNIX for Dummies Questions & Answers

deleting specific lines from all files in a directory

I have a directory full of text data files. Unfortunately I need to get rid of the 7th and 8th line from them all so that I can input them into a GIS application. I've used an awk script to do one at a time but due to the sheer number of files I need some kind of loop mechanism to automate... (3 Replies)
Discussion started by: vrms
3 Replies

10. Shell Programming and Scripting

Deleting specific lines in a file

I have a file which has some lines starting with a particular word. I would like to delete 5 lines before each such line containing that particular word. eg: line1 line2 line3 line4 line5 line6 "particular word"... I would like to delete line2-line6 and all such occurences in that... (4 Replies)
Discussion started by: ramu_1980
4 Replies
Login or Register to Ask a Question