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
DELETE(7)							   SQL Commands 							 DELETE(7)

NAME
DELETE - delete rows of a table SYNOPSIS
DELETE FROM [ ONLY ] table [ WHERE condition ] INPUTS table The name (optionally schema-qualified) of an existing table. condition This is an SQL selection query which returns the rows which are to be deleted. Refer to the SELECT statement for further description of the WHERE clause. OUTPUTS DELETE count Message returned if items are successfully deleted. The count is the number of rows deleted. If count is 0, no rows were deleted. DESCRIPTION
DELETE removes rows which satisfy the WHERE clause from the specified table. If the condition (WHERE clause) is absent, the effect is to delete all rows in the table. The result is a valid, but empty table. Tip: TRUNCATE [truncate(7)] is a PostgreSQL extension which provides a faster mechanism to remove all rows from a table. By default DELETE will delete tuples in the table specified and all its sub-tables. If you wish to only update the specific table men- tioned, you should use the ONLY clause. You must have write access to the table in order to modify it, as well as read access to any table whose values are read in the condition. USAGE
Remove all films but musicals: DELETE FROM films WHERE kind <> 'Musical'; SELECT * FROM films; code | title | did | date_prod | kind | len -------+---------------------------+-----+------------+---------+------- UA501 | West Side Story | 105 | 1961-01-03 | Musical | 02:32 TC901 | The King and I | 109 | 1956-08-11 | Musical | 02:13 WD101 | Bed Knobs and Broomsticks | 111 | | Musical | 01:57 (3 rows) Clear the table films: DELETE FROM films; SELECT * FROM films; code | title | did | date_prod | kind | len ------+-------+-----+-----------+------+----- (0 rows) COMPATIBILITY
SQL92 SQL92 allows a positioned DELETE statement: DELETE FROM table WHERE CURRENT OF cursor where cursor identifies an open cursor. Interactive cursors in PostgreSQL are read-only. SQL - Language Statements 2002-11-22 DELETE(7)
All times are GMT -4. The time now is 02:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy