Add 0 values to replace empty value


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Add 0 values to replace empty value

Hi Guys.

Please can you help me to add 0 values. Starting in column 121

Imput file

Code:
A          4175.0  8055.01211 75   1  -2172671 77 45 16 457626.4 2609265.1 131.3  1090 102 1                   1T N/A124    15 0.8    1051670971100000
A          4175.0  8055.012 7 75   2  -5204072 78 43 25 457627.7 2609284.5 131.8  1090 102 1                   1T N/A124    15 0.8    1051670971100000
A          4173.0  8055.01211 75   1  -3142772 77 61 18 457624.6 2609212.6 131.1  1089 102 1                   1T N/A124   009 0.8    1051671025148000
A          4173.0  8055.012 7 75   1  -3132772 79 61 16 457625.2 2609231.2 131.1  1089 102 1                   1T N/A124   009 0.8    1051671025148000
A          4171.0  8055.01211 75   1   3142671 77 40 26 457622.6 2609161.0 131.6  1088 102 1                   1T N/A124  5121 0.8    1051671097224000
A          4171.0  8055.012 7 75   1   3162772 77 48 20 457622.2 2609179.5 131.2  1088 102 1                   1T N/A124  5121 0.8    1051671097224000
A          4169.0  8055.01211 75   1   3152571 77 34 26 457625.4 2609110.6 131.9  1087 102 1                   1T N/A124 55215 0.8    1051671151300000
A          4169.0  8055.012 7 75   1  -2172972 78 43 27 457624.3 2609129.2 131.8  1087 102 1                   1T N/A124 55215 0.8    1051671151300000
A          4167.0  8055.01211 75   1   3162971 75 36 25 457626.9 2609064.4 131.6  1086 102 1                   1T N/A124155327 0.8    1051671223416000
A          4167.0  8055.012 7 75   1  -3142772 76 43 26 457627.0 2609083.5 132.5  1086 102 1                   1T N/A124155327 0.8    1051671223416000

Desire output

Code:
A          4175.0  8055.01211 75   1  -2172671 77 45 16 457626.4 2609265.1 131.3  1090 102 1                   1T N/A124000015 0.8    1051670971100000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4175.0  8055.012 7 75   2  -5204072 78 43 25 457627.7 2609284.5 131.8  1090 102 1                   1T N/A124000015 0.8    1051670971100000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4173.0  8055.01211 75   1  -3142772 77 61 18 457624.6 2609212.6 131.1  1089 102 1                   1T N/A124000009 0.8    1051671025148000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4173.0  8055.012 7 75   1  -3132772 79 61 16 457625.2 2609231.2 131.1  1089 102 1                   1T N/A124000009 0.8    1051671025148000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4171.0  8055.01211 75   1   3142671 77 40 26 457622.6 2609161.0 131.6  1088 102 1                   1T N/A124005121 0.8    1051671097224000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4171.0  8055.012 7 75   1   3162772 77 48 20 457622.2 2609179.5 131.2  1088 102 1                   1T N/A124005121 0.8    1051671097224000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4169.0  8055.01211 75   1   3152571 77 34 26 457625.4 2609110.6 131.9  1087 102 1                   1T N/A124055215 0.8    1051671151300000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4169.0  8055.012 7 75   1  -2172972 78 43 27 457624.3 2609129.2 131.8  1087 102 1                   1T N/A124055215 0.8    1051671151300000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4167.0  8055.01211 75   1   3162971 75 36 25 457626.9 2609064.4 131.6  1086 102 1                   1T N/A124155327 0.8    1051671223416000                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
A          4167.0  8055.012 7 75   1  -3142772 76 43 26 457627.0 2609083.5 132.5  1086 102 1                   1T N/A124155327 0.8    1051671223416000

Your help is appreciated Smilie
# 2  
Is it a fixed length file? I mean length of the each line remains same
# 3  
Hi vidyadhar85,

Yes it is fix length for each line
# 4  
Quote:
Originally Posted by jiam912
Hi vidyadhar85,

Yes it is fix length for each line
Then try below..

Code:
 
awk '{v=substr($0,115,12);gsub(/ /,"0",v);print substr($0,1,114) v substr($0,127)}' filename

Note: this can be made much shorter Smilie
# 5  
Thanks vidyadhar85

It works fine
# 6  
Code:
awk ' { printf("%s%06d%s\n", substr($0,1,120), substr($0,121,6), substr($0,127)) } ' file

This User Gave Thanks to anbu23 For This Post:
# 7  
Code:
gawk 'BEGIN{FIELDWIDTHS="120 6 80"} {gsub(FS,0,$2)}1' OFS= file

This User Gave Thanks to Scrutinizer For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #52
Difficulty: Easy
A magnetic disc array is an example of offline storage.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace values

Gents, Can you please help with this. Input file 49955 2009 2 49957 2010 2 49959 2010 2 49961 2010 2 49963 2010 2 49789 2011 -174 49791 2011 2 49793 2011 2 49795 2011 2 49965 2011 170 49967 2011 2 49969 2011 2 49971 2011 2 49797 2012 -174 49799 2012 2 (8 Replies)
Discussion started by: jiam912
8 Replies

2. Shell Programming and Scripting

Replace values

Gents, Please can you help me with this. When column 49 == 2 Need to do the following changes; Change previous row field (substr$0,45,4)-1 Change previous row field (substr$0,72,5)+2 Change actual row field (substr$0,40,4)+1 Change actual row field (substr$0,49,1)-1 Change actual... (6 Replies)
Discussion started by: jiam912
6 Replies

3. Shell Programming and Scripting

Need command to replace empty using sed/awk

Hi, In a file we have the following data like as below abcdef="cfg-1-15" bmmdda-g-45-2 yhdiao"rtg-1-df-34" I need a sed/awk command to replace the above string with empty. Thx, (1 Reply)
Discussion started by: kirankumar
1 Replies

4. Shell Programming and Scripting

Replace space with empty

Hi All, My Input is: 111.121 23212121 121.231 12678878 My output should be 111.12123212121 121.23112678878 in each row i need to replace that perticular space with empty. 8th position in the file for all rows. Please help me in this case .. Thanks (7 Replies)
Discussion started by: raju4u
7 Replies

5. Shell Programming and Scripting

Replace empty string on particular column

Hi I would like to replace empty string with a particluar value, any suggessions with awk ? my input file is not delimited with any delimiters input 52001073M8000000004567777 5200107 000000004567778 5200107 000000004567779 52001073M8000000004567789 Expected output... (5 Replies)
Discussion started by: selvankj
5 Replies

6. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

7. Shell Programming and Scripting

Replace all found files with an empty file?

Hi all, I need to replace certain robots.txt files with an empty file. I use the following to find the files I want to empty out: find /Sites -type f -name "robots.txt" -exec grep -il "STAGE" {} \; (finds all robots.txt files which contain the string 'STAGE') Now what do I add to this... (3 Replies)
Discussion started by: Evert
3 Replies

8. Shell Programming and Scripting

how to add empty filed to record

hi i have record looks like below 1,US I want to add empty field to the record as below 1, , , ,US how i can do it using awk ? i tried with awk its not working awk '{ print $1", ,"$2 }' filename > file 1 (2 Replies)
Discussion started by: raghavendra.cse
2 Replies

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

Featured Tech Videos