Ignore records with no values through awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore records with no values through awk
# 1  
Old 02-08-2011
Ignore records with no values through awk

Hi Guys,
Hope you are doing well out there.

I have to format the output of a script.

Current output is
Code:
 auktltbr.dc-dublin.de:4322 ICCIR2Test13-PB-01 active
auktltbr.dc-dublin.de:8322 ICCIR2Test13-SB-02 active
auktlttr.dc-dublin.de:4422 ICCIR2Test24-CB-02 active
auktlttr.dc-dublin.de:5422 ICCIR2Test24-CB-01 active
auktltur.dc-dublin.de:6422
auktlttr.dc-dublin.de:7422 ICCIR2Test24-SB-01 active
auktlttr.dc-dublin.de:7423
auktltur.dc-dublin.de:4422
auktltur.dc-dublin.de:5422
auktltur.dc-dublin.de:7422 ICCIR2Test24-SB-02 active

I want it to be like
Code:
 auktltbr.dc-dublin.de:4322 ICCIR2Test13-PB-01 active
auktltbr.dc-dublin.de:8322 ICCIR2Test13-SB-02 active
auktlttr.dc-dublin.de:4422 ICCIR2Test24-CB-02 active
auktlttr.dc-dublin.de:5422 ICCIR2Test24-CB-01 active
auktlttr.dc-dublin.de:7422 ICCIR2Test24-SB-01 active
auktltur.dc-dublin.de:7422 ICCIR2Test24-SB-02 active

That is ignore the records which have null values in 2nd coloumn.

I want to achive this using awk.

Any help, would be highly appereciated.

Thanks,
Chandan
# 2  
Old 02-08-2011
Try:
Code:
awk NF-1 infile

# 3  
Old 02-08-2011
Or:
Code:
awk '$2' file

# 4  
Old 02-08-2011
Code:
awk NF!=1 infile

# 5  
Old 02-09-2011
Thanks for your help, Guys.

All the solutions work perfectly.

Thanks,
Chandan
# 6  
Old 02-09-2011
Hi

Can you please explain what is the meaning of the statement



awk NF-1 infile

how it ignores the coloums which has no value

and also of the below code

awk '$2' infile


Thanks
# 7  
Old 02-09-2011
Hi,

I am not pretty sure about awk 'NF-1'. But the second one (awk '$2' infile) means, it will only show the records which have 2 or more fields, pupulated with strings. If you give awk '$4' infile, it will only output the records those have 4 or more fields. Please see below.

Code:
$ awk '$2' EMS_Status.txt
auktltar.dc-dublin.de:5922 ICCIR2Test09-CB-01 active
auktltbr.dc-dublin.de:6922 ICCIR2Test09-RB-01 active
auktltar.dc-dublin.de:7922 ICCIR2Test09-SB-01 active
auktltar.dc-dublin.de:5522 ICCIR2Test06-CB-01 active Server:
auktltar.dc-dublin.de:7622 ICCIR2Test06-SB-01 active

Code:
$ awk '$4' EMS_Status.txt
auktltar.dc-dublin.de:5522 ICCIR2Test06-CB-01 active Server:

---------- Post updated at 07:37 PM ---------- Previous update was at 07:33 PM ----------

Hi Scrutinizer.

Could you please explain the meaning of awk NF-1.

Thank You,
Chandan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting cut to ignore cols in middle of records

I recently had to remove a number of columns from a sorted copy of a file, but couldn't get the cut command to take fields out, just what to keep. This is the only thing I could find as an example, but could it be simplified? tstamp=`date +%H%M%S` grep -v "T$" filename |egrep -v "^$" |sort... (3 Replies)
Discussion started by: wbport
3 Replies

2. Shell Programming and Scripting

awk to ignore whitespace in field

The awk below executes and update the desired field in my first awk. However, the white space between nonsynonymous SNV in $9 is being split into tabs and my attempt to correct this does not update the field unless it is removed. I am not sure what I am doing wrong? Thank you :). file1 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Programming

Subtract values based on records

Hi Guys, I am having below tables in oracle T1 ID F_TYPE F_AMT DATE_COL 1 F 6 11-Feb-16 1 D 2 11-Feb-16 1 D 2 11-Feb-16 1 F 6 11-Feb-16 1 F 2 12-Mar-16 1 D 3 12-Mar-16 1 F 4 10-Apr-16 1 F 4 11-Apr-16 1 D 1 11-Apr-16 T2 ID START_DATE END_DATE F_ID FLAG... (0 Replies)
Discussion started by: rohit_shinez
0 Replies

4. Shell Programming and Scripting

Clean values in range of duplicate records

Dear Gents, Could you please help me to solve this problem. I am getting the average of a column for same duplicate records in this case locate in column 1. The average is computed from column 5 from all duplicate records in column 1. Normallly the values in column 5 is constant so the... (3 Replies)
Discussion started by: jiam912
3 Replies

5. Shell Programming and Scripting

Copy header values into records

I'm using a shell script to manipulate a data file. I have a large file with two sets of data samples (tracking memory consumption) taken over a long period of time, so I have many samples. The problem is that all the data is in the same file so that each sample contains two sets of data.... (2 Replies)
Discussion started by: abercrom
2 Replies

6. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

7. Shell Programming and Scripting

awk to ignore the text before a particular word

Hi I am new to Awk programming , i would appreciate if anyone help me with the below scenario i have text file arranged in rows and columns like below 11004 04493384 26798 CASSI0000I Server manager initialization started 111004 04493486 26798 CASSI4005I Retrieving ES... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

8. Shell Programming and Scripting

verifying column2 for same kind of records and adding corresponding values in column3

Hi am having a file which looks like this i want to get unique values in column2 and sum up the corresponding column3 values and discard the column4 and then write the output in different file. i.e the output has to be like i.e 07-Jun-2009 919449829088 52 lessrv1 07-Jun-2009... (2 Replies)
Discussion started by: aemunathan
2 Replies

9. Shell Programming and Scripting

awk, ignore first x number of lines.

Is there a way to tell awk to ignore the first 11 lines of a file?? example, I have a csv file with all the heading information in the first lines. I want to split the file into 5-6 different files but I want to retain the the first 11 lines of the file. As it is now I run this command: ... (8 Replies)
Discussion started by: trey85stang
8 Replies

10. UNIX for Dummies Questions & Answers

Generating key values for leader records

All, I have a file with text as shown below. I want the o/p file with generated values in the first column as shown in the o/p file. Pls note that the size of my file is 6 GB. How do i do this ? Input file 999999abcdef 999999ghijkl 999999mnopq 777777rosesarered 777777skyisblue Output... (1 Reply)
Discussion started by: ajfaq
1 Replies
Login or Register to Ask a Question