Sponsored Content
Top Forums Shell Programming and Scripting How to detect empty field in awk ? Post 302793467 by Dona Clara on Friday 12th of April 2013 12:25:06 PM
Old 04-12-2013
How to detect empty field in awk ?

Hi ! programmers

I have a need of detecting empty field in file
my file looks like this

Code:
40.900|-71.600|1.6|20|1|1961|21.00|3.700||1|US|28035|10029370|31
40.900|-71.600|5.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31
40.900|-71.600|7.8|20|1|1961|21.00|3.700||1|US|28035|10029370|31
40.900|-71.600|8.5|20|1|1961|21.00|3.700||1|US|28035|10029370|31
40.900|-71.600|8.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31
-26.667|12.483|1.3|24|1|1961|20.00|16.530|35.059|4|ZA|3|8756280|80
-26.667|12.483|2.5|24|1|1961|20.00|16.530|35.061|4|ZA|3|8756280|80
-26.667|12.483|8.1|24|1|1961|20.00|16.530|35.060|4|ZA|3|8756280|80
40.900|-71.600|8.7|20|1|1961|21.00|3.700||1|US|28035|10029370|31
-26.667|12.483|12.4|24|1|1961|20.00|16.530|35.059|4|ZA|3|8756280|80
-26.667|12.483|13.7|24|1|1961|20.00|16.250|35.035|4|ZA|3|8756280|80
-26.667|12.483|15.9|24|1|1961|20.00|15.860|34.982|4|ZA|3|8756280|80
-26.667|12.483|31.4|24|1|1961|20.00|13.020|34.925|4|ZA|3|8756280|80
-26.667|12.483|34.8|24|1|1961|20.00|13.000|34.999|4|ZA|3|8756280|80

in first column 9th column is empty, in another column 15 column may be empty...so like this I have many files
wherever field is empty I want to print string "BAD" in that location, I need solution for both FS="|" as well as mixed FS tab+space+no of empty spaces

expecting o/p like this
Code:
40.900|-71.600|1.6|20|1|1961|21.00|3.700|BAD|1|US|28035|10029370|31
40.900|-71.600|5.7|20|1|1961|21.00|3.700|BAD|1|US|28035|10029370|31
40.900|-71.600|7.8|20|1|1961|21.00|3.700|BAD|1|US|28035|10029370|31

Those who have solution please help. quick reply will be helpful

Last edited by Dona Clara; 04-12-2013 at 01:40 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk scrip to remove empty field

Hi I have a file which looks like this name: Sally group: Group4 name: Tim group: Group1 name: Dan group: Group2 name: Chris group: Group3 name: Peter group: name: Fred group: name: Mary group: Group2 Well I want to get rid of the... (4 Replies)
Discussion started by: bombcan
4 Replies

2. UNIX for Dummies Questions & Answers

Count of Field for Non-Empty

Hi Guys, I wanted to count the number of records for a particular field of a file. whose fields are separated by comma"," I fI use this command. cat "filename" cut -sd "," -f13 | wc -l This shows all the lines count including the blank values for the field number 13. I wanted to count... (2 Replies)
Discussion started by: Swapna173
2 Replies

3. Shell Programming and Scripting

awk - if field is empty, move line to new file

I have a script with this statement: /usr/xpg4/bin/awk -F"" 'NR==FNR{s=$2;next}{printf "%s\"%s\"\n", $0, s}' LOOKUP.TXT finallistnew.txt >test.txt I want to include logic or an additional step that says if there is no data in field 3, move the whole line out of test.txt into an additional... (9 Replies)
Discussion started by: scriptr2be
9 Replies

4. Shell Programming and Scripting

use awk to replace empty fields with the latest nonempty field

Hi suppose I have a csv file like this count,1977,1978,1979 usa, , , blue japan, red, yellow,green india, , yellow,blue china, blue, yellow, green I want the output to be(replace everything, including empty data, with the most recent data): ... (1 Reply)
Discussion started by: grossgermany
1 Replies

5. Shell Programming and Scripting

Format the file by deleting empty field

I have the test data with 10 column separated by comma and each column has more than 1000000 rows. Can anyone help me to find empty field in all columns and delete that empty field alone and lift that column up by one row. Data with empty field: A74203XYZ,A21718XYZ,A72011XYZ,A41095XYZ,... (7 Replies)
Discussion started by: zooby
7 Replies

6. Shell Programming and Scripting

awk - remove row if specific field is empty/blank

I have this text.filecharles darwin sam delight george washington johnson culper darwin sam delight micheal jackson penny lite and would like to remove the row, if the first field is blank. so the result would be: result.filecharles darwin sam ... (4 Replies)
Discussion started by: charles33
4 Replies

7. UNIX for Dummies Questions & Answers

remove empty field

Hi all ! I'm sure it is a basic question but I didn't find any threads that fit my need. How to remove empty fields with awk? Or in other words, how to shift all the fields after an empty field on the left? input: 1|2||3|4|5||6 wanted: 1|2|3|4|5|6 I tried: awk '{for(i=1; i<=NF;... (7 Replies)
Discussion started by: lucasvs
7 Replies

8. Shell Programming and Scripting

print non empty column/field value

I have below file 25-09-2012 24-09-2012 19-09-2012 31-07-2012 30-04-2012 30-03-2012 ASIAEXFVNV N/A CEU 4 DMIRSOA N/A CAS 2 2 2 DMIRSOA N/A MIDMT 2 NFIAL22 N/A HVNY 11 11 11 NFIAL22 N/A NYAL3 11 11 11 NFIAL22 N/A NYCN 11 11 11 ... (4 Replies)
Discussion started by: manas_ranjan
4 Replies

9. Web Development

Php help to copy form field if empty

I have an input form with several fields. What I would like to achieve is to auto populate or copy certain fields if they are empty when the form is submitted. I would like to use php if not then javascript but not jquery if possible - I have sort of had a go but I really have no idea... (4 Replies)
Discussion started by: barrydocks
4 Replies

10. UNIX for Dummies Questions & Answers

Using awk to remove duplicate line if field is empty

Hi all, I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following: FILE: 1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100 2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY) 3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies
priority.h(3)							       log4c							     priority.h(3)

NAME
priority.h - The priority class provides importance levels with which one can categorize log messages. SYNOPSIS
#include <log4c/defs.h> Enumerations enum log4c_priority_level_t { LOG4C_PRIORITY_FATAL = 000, LOG4C_PRIORITY_ALERT = 100, LOG4C_PRIORITY_CRIT = 200, LOG4C_PRIORITY_ERROR = 300, LOG4C_PRIORITY_WARN = 400, LOG4C_PRIORITY_NOTICE = 500, LOG4C_PRIORITY_INFO = 600, LOG4C_PRIORITY_DEBUG = 700, LOG4C_PRIORITY_TRACE = 800, LOG4C_PRIORITY_NOTSET = 900, LOG4C_PRIORITY_UNKNOWN = 1000 } Functions LOG4C_API const char * log4c_priority_to_string (int a_priority) LOG4C_API int log4c_priority_to_int (const char *a_priority_name) Detailed Description The priority class provides importance levels with which one can categorize log messages. Enumeration Type Documentation enum log4c_priority_level_t Predefined Levels of priorities. These correspond to the priority levels used by syslog(3). Enumerator: LOG4C_PRIORITY_FATAL fatal LOG4C_PRIORITY_ALERT alert LOG4C_PRIORITY_CRIT crit LOG4C_PRIORITY_ERROR error LOG4C_PRIORITY_WARN warn LOG4C_PRIORITY_NOTICE notice LOG4C_PRIORITY_INFO info LOG4C_PRIORITY_DEBUG debug LOG4C_PRIORITY_TRACE trace LOG4C_PRIORITY_NOTSET notset LOG4C_PRIORITY_UNKNOWN unknown Function Documentation LOG4C_API int log4c_priority_to_int (const char *a_priority_name) Parameters: a_priority_name a priority string name. Returns: the given numeric value of the priority. References LOG4C_PRIORITY_UNKNOWN. LOG4C_API const char* log4c_priority_to_string (inta_priority) Parameters: a_priority a numeric value of the priority. Returns: the given priority string name. Author Generated automatically by Doxygen for log4c from the source code. Version 1.2.1 Mon May 2 2011 priority.h(3)
All times are GMT -4. The time now is 06:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy