Replace a field where values are null in a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace a field where values are null in a file.
# 8  
Old 06-05-2013
@MadeInGermany
Code:
$3~/^$/

So this is the only solution that represent an empty filed.
Thanks for the information Smilie
# 9  
Old 06-09-2013
@juzzfun, Jotne: if you do not use quotes it will shave off the leading zero of 099990
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 06-09-2013
Quote:
Originally Posted by MadeInGermany
Note that 1.
Code:
!$3

also replaces fields with 0 or 00,
while 2.
Code:
$3~/^$/

only replaces empty fields.
We had a discussion in another thread about $3=="" that IMHO should be equal to 2.
But Solaris /usr/xpg4/bin/awk (since the patch for bugID 5074811) treats it like 1.
Could you please give me a pointer to the other thread?

I'm curious as to why you believe $3=="" should evaluate to 2 when $3 is an empty field. The standards say:
Quote:
The value of the comparison expression shall be 1 if the relation is true, or 0 if the relation is false.
and a comparison expression is an expression using one of the operators <, <=, !=, ==, >=, or >.
# 11  
Old 06-09-2013
Quote:
Originally Posted by Don Cragun
I'm curious as to why you believe $3=="" should evaluate to 2 when $3 is an empty field.
Hi Don, may be you didn't read MadeInGermany's reply carefully (or may be it was not well explained). I think he meant that $3=="" is equivalent to $3~/^$/ (the 2nd code fragment in his post).
These 2 Users Gave Thanks to elixir_sinari For This Post:
# 12  
Old 06-10-2013
Quote:
Originally Posted by juzz4fun
I can use nawk, but just wondering why awk is not working with 1 on my machine Smilie
solaris keeps a stone-age awk around for compatibility reasons. To get the language everyone expects awk to be these days, you use nawk.
# 13  
Old 06-10-2013
Quote:
Originally Posted by Corona688
solaris keeps a stone-age awk around for compatibility reasons. To get the language everyone expects awk to be these days, you use nawk.
They still ship this in SysV R4.0 style i.e. link awk with oawk:
Code:
ls -li /usr/bin/*awk
     54765 -r-xr-xr-x   2 root     bin        89108 Oct  1  2007 /usr/bin/awk
     54744 -r-xr-xr-x   1 root     bin       126944 Oct  1  2007 /usr/bin/nawk
     54765 -r-xr-xr-x   2 root     bin        89108 Oct  1  2007 /usr/bin/oawk

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace the field values, which are greater than the specified value with TRUE?

I have a csv file as given below, org1 org2 org3 org4 org5 gene1 100 80 90 80 150 gene2 30 70 50 50 115 gene3 40 120 60 40 105 gene4 20 72 40 60 20 I need to replace the fields are having values greater than 100 with "TRUE". I used the following commands to replace... (6 Replies)
Discussion started by: dineshkumarsrk
6 Replies

2. Shell Programming and Scripting

Replace null values with dot using awk

Using awk I am trying to replace all blank or null values with a . in the tad delimited input. I hope the awk is close. Thank you :). input name test sam 1 liz 2 al 1 awk awk 'BEGIN{FS=OFS="\t"}{for(i=1;++i<NF;)$i=$i?$i:"."}1'input awk 'BEGIN { FS =... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

Multiple columns replace with null values.

I am trying to replace the partcular columns(Col3,col5,col20,col44,col55,co56,col59,col60,col61,col62,col74,col75,col88,col90,col91,col93,col94,col95) with empty Input file Col1,col2,col3,col4,col5------,col100 1,2,3,4,5,---------,100 3,4,5,6,7,---------,300 Output : ... (3 Replies)
Discussion started by: onesuri
3 Replies

4. Shell Programming and Scripting

Replace null values in csv with zero

Hi, i have another issue: i have three files: FILE 1 ServiceEventHandler, Processed,Percentage 5285337,100% FILE 2 Wallet, Processed,Percentage 5285337,100% (1 Reply)
Discussion started by: reignangel2003
1 Replies

5. Shell Programming and Scripting

Find a blank field and replace values to NA

Hi All, i have a file like col1 col2 col3 13 24 NA 12 13 14 11 12 13 14 22 NA 18 26 NA in this file if i found "NA" other values in the line are also replace by NA Could you help me! (7 Replies)
Discussion started by: Shenbaga.d
7 Replies

6. Shell Programming and Scripting

To find char field and replace null

hi, i having a file with | seperated in which i need to search char in 3rd column and replace with null. i need to replace only the coulmn where character occurs in 3rd field for eg: file1.txt xx|yy|xx|12 output file: xx|yy||12 (5 Replies)
Discussion started by: rohit_shinez
5 Replies

7. Shell Programming and Scripting

File values alwaya null

Hi All , below is my shell program. !/bin/sh set -x #---------------------------------------------------------------------------------------- # Program : weekly_remove_icd_file.sh # Author : # Date : 04/06/2013 # Purpose : Execute the script to... (3 Replies)
Discussion started by: krupasindhu18
3 Replies

8. Shell Programming and Scripting

Replace 4th field if null

Hi .. Can some one please suggest me how to replace 4th field(column) of a .csv file with "NA" if it is null. Input file data: |A|21|B1||1.1| |A|21|C|RAGH|1.1| |A|21|D1||1.1| |A|21|C|YES|1.1 Expected Output |A|21|B1|NA|1.1| |A|22|C|RAGH|1.1| |B|23|D1|NA|1.1| |A|24|C|YES|1.1| Thank... (4 Replies)
Discussion started by: pasupuleti81
4 Replies

9. Shell Programming and Scripting

identifying null values in a file

I have a huge file with 20 fileds in each record and each field is seperated by "|". If i want to get all the reocrds that have 18th or for that matter any filed as null how can i do it? Please let me know (3 Replies)
Discussion started by: dsravan
3 Replies
Login or Register to Ask a Question