Remove first 3 leadings zeros and replace with space

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Remove first 3 leadings zeros and replace with space
# 1  
Old 10-09-2017
Remove first 3 leadings zeros and replace with space

Hi Folks -

I need help manipulating a file.

For column 2, I need to replace the first 3 leading zeros with spaces.

The file looks like such:

Code:
00098|00011250000003|00000000000.0200|D|1|07|51|04INDP    |04|00820|CS|000000|092717|000000000000.0000|000|
00098|000011250000003|00000000000.0200|D|1|07|51|04INDP    |04|00820|CS|000000|092717|000000000000.0000|000|
00098|00011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|000011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|000011250000063|00000000032.8500|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000035.5200|000|
00098|000011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|000011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|00011200000053|00000000075.0000|D|6|03|51|04INDP    |04|00820|CC|000000|092717|000000000000.0000|000|
00098|000953905002285|00000000065.0000|C| |99|00|04INDP    |04|01530|SM|000000|092717|000000000000.0000|000|
00098|000019000016491|00000000062.5000|D|3|99|00|04INDP    |04|01530|CM|000000|092717|000000000000.0000|000|
00098|000051260000003|00000000002.4000|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|000051260000003|00000000000.3400|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|00051260000003|00000000000.5200|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|00051260000054|00000000050.6800|D|1|04|00|04INDP    |04|03006|CS|-00002|092717|-00000000049.6800|333|
00098|000051260000054|00000000033.1700|D|1|04|00|04INDP    |04|03006|CS|-00001|092717|-00000000032.5200|333|
00098|000051260000054|00000000226.6000|D|1|04|00|04INDP    |04|03006|CS|-00010|092717|-00000000291.6000|333|

I tried sed but can't get anything to work.
Thanks!
# 2  
Old 10-09-2017
Assuming they are always zeros..
Code:
$ sed "s/|000/|   /" t.txt
00098|   11250000003|00000000000.0200|D|1|07|51|04INDP    |04|00820|CS|000000|092717|000000000000.0000|000|
00098|   011250000003|00000000000.0200|D|1|07|51|04INDP    |04|00820|CS|000000|092717|000000000000.0000|000|
00098|   11250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|   011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|   011250000063|00000000032.8500|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000035.5200|000|
00098|   011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|   011250000063|00000000011.1100|D|1|07|51|04INDP    |04|00820|CS|-00001|092717|-00000000012.6000|000|
00098|   11200000053|00000000075.0000|D|6|03|51|04INDP    |04|00820|CC|000000|092717|000000000000.0000|000|
00098|   953905002285|00000000065.0000|C| |99|00|04INDP    |04|01530|SM|000000|092717|000000000000.0000|000|
00098|   019000016491|00000000062.5000|D|3|99|00|04INDP    |04|01530|CM|000000|092717|000000000000.0000|000|
00098|   051260000003|00000000002.4000|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|   051260000003|00000000000.3400|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|   51260000003|00000000000.5200|D|1|04|00|04INDP    |04|03006|CS|000000|092717|000000000000.0000|333|
00098|   51260000054|00000000050.6800|D|1|04|00|04INDP    |04|03006|CS|-00002|092717|-00000000049.6800|333|
00098|   051260000054|00000000033.1700|D|1|04|00|04INDP    |04|03006|CS|-00001|092717|-00000000032.5200|333|
00098|   051260000054|00000000226.6000|D|1|04|00|04INDP    |04|03006|CS|-00010|092717|-00000000291.6000|333|

Otherwise, any three characters..
Code:
$ sed "s/|.../|   /"

# 3  
Old 10-09-2017
Wow this was perfect!!! Thank you!
# 4  
Old 10-09-2017
Hello SIMMS7400,

Could you please try following awk too and let me know if this helps you.
Code:
awk --re-interval -F"|" '{sub(/^0{3}/,"",$2)} 1' OFS="|"   Input_file

I have old version of awk, so in case you have latest version of awk, you could use it without --re-interval too.

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove trailing zeros from numbers

Hi, I am trying to remove trailing zeros from numbers in a csv file. CSV Input : 0.5000,abc,2.00,2.400,285.850,285a.850,205.180800,mno000,a0b0,2.860 Expected Output : .5,abc,2,2.4,285.85,285a.850,205.1808,mno000,a0b0,2.86 Can you please help. Thanks. (11 Replies)
Discussion started by: manubatham20
11 Replies

2. Shell Programming and Scripting

Remove leading zeros separated by pipe

I have a below file and I wanted to remove the leading zeros in each field separated by pipe File: 01/09/2017|2017/09/06|2017/02/06|02/06/2017|02/06/2017 06:50:06 AM|2017/02/06|02/06/2017|02/07/2017 05:45:06 AM| 02/08/2017|2017/08/06|2017/09/06|02/05/2017|02/07/2017 05:40:06... (4 Replies)
Discussion started by: Joselouis
4 Replies

3. Shell Programming and Scripting

Ho to remove leading zeros from a csv file which is sent from a UNIX script

Hi All, I am using a informatica job to create a csv file and a unix script the mail the generated file.Everything is working fine but I am not seeing leading zeros in the csv file sent in the mail.These zeros were present when the .csv file was generated by informatica procees. Is there any... (11 Replies)
Discussion started by: karthik adiga
11 Replies

4. UNIX for Beginners Questions & Answers

Remove characters and replace with space

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file This removes special characters but how can I replace it with space (4 Replies)
Discussion started by: eskay
4 Replies

5. Shell Programming and Scripting

Fixed with file- removing leading zeros and adding the space

Hi All, i have a fixed width file , where each line is 3200 length. File: 1ABC 1111 2222 3333 000012341 1001 2ABC 1111 2222 3333 000012342 1002 3ABC 1111 2222 3333 000112343 1003 1DEF 5555 4444 9696 000012344 1004 2DEF 5555 2323 8686 000012345 1005 3DEF 5555 1212 7676 000012346 1006 ... (1 Reply)
Discussion started by: mechvijays
1 Replies

6. UNIX for Dummies Questions & Answers

Remove zeros from first field, but print all fields

Hello Everyone, I've got a comma-delimited file that looks like this: 0012,123 ,456 ,05/12/2014 0123,525 ,286 ,05/12/2014 0456,791 ,300 ,05/12/2014 1095,759 ,300 ,05/12/2014 1344,576 ,292 ,05/12/2014 1558,551 ,283 ,05/12/2014 002183719, , ... (9 Replies)
Discussion started by: Scottie1954
9 Replies

7. Shell Programming and Scripting

Remove trailing zeros

Hi I have a simple request but can't find the answer. I want to remove trailing zeros, and in some cases the fullstops, from the input data. Example of input file: FR002_15.000_20.000 SD475_5.000_10.500 FG5647_12.250_15.500 BH2463_30.555_32.000 Desired output file would be: ... (10 Replies)
Discussion started by: theflamingmoe
10 Replies

8. Shell Programming and Scripting

awk to remove leading zeros for a hex number

Is it possible by using awk to remove leading zeros for a hex number? ex: 0000000011179E0A -> 11179E0A Thank you! (4 Replies)
Discussion started by: carloszhang
4 Replies

9. Shell Programming and Scripting

Remove O and preceeding zeros in a string

Hi all, Can anybody help me out to write a program in perl to remove O and preceeding zeros. for eg input is O0000123089 - output 123089 Thanks Mahalakshmi.A (10 Replies)
Discussion started by: mahalakshmi
10 Replies

10. Shell Programming and Scripting

remove precursing zeros

Hello all, I have a list of reports for stores that are numbered like: s001845,s000022,s198490,s020048,s002385 however the users are displaying the reports as: 1845,22,198490,20048,2385 It isn't real critical but I would like to associate them so they are the same. And since the users are... (2 Replies)
Discussion started by: gozer13
2 Replies
Login or Register to Ask a Question