How to print with awk specific field different from specific character?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print with awk specific field different from specific character?
# 1  
Old 08-22-2013
How to print with awk specific field different from specific character?

Hello,

i need help with awk.
I have this file:

Code:
cat number
DirB    port    67      er_enc_out      0       er_bad_os       0
DirB    port    71      er_enc_out      56       er_bad_os       0
DirB    port    74      er_enc_out      0       er_bad_os       0
DirB    port    75      er_enc_out      0       er_bad_os       45
DirB    port    76      er_enc_out      0       er_bad_os       0
DirB    port    77      er_enc_out      0       er_bad_os       0
DirB    port    78      er_enc_out      12       er_bad_os       0
DirB    port    79      er_enc_out      0       er_bad_os       0
DirB    port    202     er_enc_out      0       er_bad_os       0
DirB    port    203     er_enc_out      0       er_bad_os       19
DirB    port    204     er_enc_out      0       er_bad_os       0
DirB    port    206     er_enc_out      4       er_bad_os       6
DirB    port    207     er_enc_out      0       er_bad_os       0
DirB    port    96      er_enc_out      0       er_bad_os       0

I need to intercept the value different from 0. like this:

DirB port 71 er_enc_out 56 er_bad_os 0
DirB port 75 er_enc_out 0 er_bad_os 45
DirB port 78 er_enc_out 12 er_bad_os 0
DirB port 203 er_enc_out 0 er_bad_os 19
DirB port 206 er_enc_out 4 er_bad_os 6

thanks
Luca
# 2  
Old 08-22-2013
Code:
awk '$5!="0"||$7!="0"' number

# 3  
Old 08-22-2013
no, i'm sorry, i need to remove the line with this field:

er_enc_out 0 er_bad_os 0
# 4  
Old 08-22-2013
I get the answer same as in your first post.
Code:
awk '$5!="0"||$7!="0"' number

DirB    port    71      er_enc_out      56       er_bad_os       0
DirB    port    75      er_enc_out      0       er_bad_os       45
DirB    port    78      er_enc_out      12       er_bad_os       0
DirB    port    203     er_enc_out      0       er_bad_os       19
DirB    port    206     er_enc_out      4       er_bad_os       6

If you get difference, please try with nawk or /usr/xpg4/bin/awk.
# 5  
Old 08-22-2013
thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

awk to combine all matching fields in input but only print line with largest value in specific field

In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited, that are in $1 of gene which is just a single column of text. However only the line with the greatest $9 value in input needs to be printed. So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Print specific field when condition met

Hi All, Seeking for your assistance to print all the specific field when the condition met. Ex: file1.txt 1|203|3|31243|5341|6452|623|22|00|01 3|45345|123214|6534|3423|6565|643|343|232|10 if field 1 = 1 and field 3 = 3 and field 5 = 5341 and field 6 = 6452 it will print from $1 to $10.... (2 Replies)
Discussion started by: znesotomayor
2 Replies

4. Shell Programming and Scripting

File Parsing based on a character in a specific field

Hi All, I'm having a hard time finding a starting point for my issue. I have a 30k line file (fspsec.txt) that I would like to parse into smaller files based on any character existing in field 1. ACCOUNTANT LEVEL 1 (ACCT.ACCOUNTANT) OPERATORS: DOEJO (418) TOOLS: Branch Maintenance ... (2 Replies)
Discussion started by: aahlrich
2 Replies

5. Shell Programming and Scripting

awk - how to print specific field if a string is matched

hi gurus, I would like to be able to use awk to process 1 file as such: abc 1 2 3 4 5 6 7 8 9 10 flags 1 2 4 flags 1 2 5 abc 2 3 4 5 6 7 8 9 10 11 flags 1 2 3 abc 4 5 6 7 8 9 6 7 78 89 flags 1 2 3 flags 1 2 4 flags 1 2 3 4 I would like to be able to print field 1 and 5 when the... (4 Replies)
Discussion started by: revaroo
4 Replies

6. Shell Programming and Scripting

Match columns and print specific field

Hello, I have data in following format. ... (6 Replies)
Discussion started by: Pushpraj
6 Replies

7. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

8. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

9. Shell Programming and Scripting

AWK Print Line If Specific Character Is Matched

Hello, I have a file as such: FFFFFFF6C000000 225280 225240 - - rwxs- FFFFFFFF79C00000 3240 3240 - - rwxs- FFFFFFFF7A000000 4096 4096 - - rwxs- FFFFFFFF7A400000 64 64 ... (3 Replies)
Discussion started by: PointyWombat
3 Replies

10. Shell Programming and Scripting

How to append a character to the last but one field on a specific line?

Hi Guys, I have a file like this: aaa b c d e f fsss g h i k l qqq r t h n I want: aaa b c d e f fsss g h i k l qqq r t h , n ggg p t e d u qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies
Login or Register to Ask a Question