Awk script to replace null columns with blank


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk script to replace null columns with blank
# 1  
Old 11-28-2011
Awk script to replace null columns with blank

I have a file with contents
Code:
"08011"||20080812
"23348"|20080827|20080924
"23387"|20080829|20080915
"23581"|20081003|20081028
"23748"|20081017|20090114
"24095"|20080919|20081013
"24105"|20070723|20070801
"24118"|20080806|20081013
"24165"|20080820|20080912
"24221"|20080908|20080929

i want to write 10 blanks in case 2 pipes are coming together in the file.
Please help using awk script

Last edited by Franklin52; 11-28-2011 at 03:32 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 11-28-2011
Code:
sed 's/||/|        |/g' inputfile

Or if you really want to do it in awk:
Code:
awk -F"|" '{ for (i=1;i<=NF;i++) { if ($i=="") { $i="        " } } OFS="|";print }' inputfile

or
Code:
awk '{gsub ("\\|\\|", "|        |"); print}' inputfile

# 3  
Old 11-28-2011
Code:
 
$ sed 's/\|\|/\|          \|/' test
"08011"|          |20080812
"23348"|20080827|20080924
"23387"|20080829|20080915
"23581"|20081003|20081028
"23748"|20081017|20090114
"24095"|20080919|20081013
"24105"|20070723|20070801
"24118"|20080806|20081013
"24165"|20080820|20080912
"24221"|20080908|20080929

# 4  
Old 11-28-2011
Code:
awk 'BEGIN{FS=OFS="|"}{for(i=1;++i<NF;)$i=$i?$i:"        "}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. UNIX for Beginners Questions & Answers

awk script to extract a column, replace one of the header and replace year(from ddmmyy to yyyy)

I have a csv which has lot of columns . I was looking for an awk script which would extract a column twice. for the first occurance the header and data needs to be intact but for the second occurance i want to replace the header name since it a duplicate and extract year value which is in ddmmyy... (10 Replies)
Discussion started by: Kunalcurious
10 Replies

3. Shell Programming and Scripting

Do replace operation and awk to sum multiple columns if another column has duplicate values

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (12 Replies)
Discussion started by: as7951
12 Replies

4. 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

5. 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

6. Shell Programming and Scripting

awk print columns which are not null

I am working on a file with several columns as below MO_NAME,FAULT_TYPE,CLASS,CODE1,CODE2,CODE3 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,53,58 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2B,24 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2A,33 RXOCF-101,BTS INTERNAL,FAULT CODES CLASS 2D,57 ... (12 Replies)
Discussion started by: Rizwan Rasul
12 Replies

7. Shell Programming and Scripting

Script to find blank records in a file except for few columns

I have a file with the following format: X|High|2|GIC|DM||XHM|||6 Months X|Moderate|2|GIC|DM||XHM|||6 Months X|High|2|GCM|DM||XSF|||6 Months X|Med|2|GCM|DM||XSF|||6 Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th... (10 Replies)
Discussion started by: chatwithsaurav
10 Replies

8. UNIX for Dummies Questions & Answers

How to find the null member or blank in the text file?

Hello All, I am new to unix scripting and wanted to know, is it possible if we find any null value or blank record in the text file. For example we have a text file with only one column and there are 90 records. But some times we will have a null value or blank row record in the text file. I... (4 Replies)
Discussion started by: Ram11111
4 Replies

9. Shell Programming and Scripting

awk command to replace columns in 2 files

Hi All, I already have a code which replaces column 14 of NPBR.XTR.tmp with column 8 of NPBR3G.XTR.final awk -F'\|' 'FNR==NR{a= $2"^"$8;next;}a{split(a,b,"^");$8=b;$14=b;}1' OFS="|" ${SHTEMP}NPBR3G.XTR.final ${SHTEMP}NPBR.XTR.tmp > ${SHTEMP}NPBR.XTR.final I also need to replace column 15... (2 Replies)
Discussion started by: nua7
2 Replies

10. Shell Programming and Scripting

Find and replace a column that has '' to NULL in a comma delimited using awk or sed

Hi this is my first time posting ever. I'm relatively new in using AWK/SED, I've been trying many a solution. I'm trying to replace the 59th column in a file where if I encounter '' then I would like to replace it with the word NULL. example 0 , '' , '' , 0 , 195.538462 change it to 0... (5 Replies)
Discussion started by: gumal901
5 Replies
Login or Register to Ask a Question