Leading zero's getting truncated on columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Leading zero's getting truncated on columns
# 1  
Old 12-11-2009
Java Leading zero's getting truncated on columns

Hi All,
I have a input file named 'inputtest.txt' like below:
HTML Code:
"335588","DW02.CAPTURED_ROC_14","13016063","00000000000001541897035.77"
"335587","DW02.NCL01_1ST_PSMT_14","446301","00000000000000040370306.43"
My desired output will be like below:
HTML Code:
335588  DW02.CAPTURED_ROC_14    13016063        001541897035.77
335587  DW02.NCL01_1ST_PSMT_14  446301          000040370306.43
I executed the below command:
Code:
sed 's/["]//g;s/[,]/     /g' inputtest.txt | awk '{ printf "%-7s\t%-18s\t%-10s\t%-12.2f\n", $1, $2, $3, $4}'

and got the output like:
HTML Code:
335588  DW02.CAPTURED_ROC_14    13016063        1541897035.77
335587  DW02.NCL01_1ST_PSMT_14  446301          40370306.43
Note: The fourth column of my output file truncates leading zero's. Please help me out on this.

Last edited by Franklin52; 12-11-2009 at 07:23 AM.. Reason: Please use code tags!
# 2  
Old 12-11-2009
Try:

Code:
awk -F, '{
  gsub("\"","")
  printf "%-7s\t%-18s\t%-10s\t%015.2f\n", $1, $2, $3, $4
}' file

# 3  
Old 12-11-2009
Java

Hi,

As per my understanding, when we use %012.2f in printf will keeps leading zero values. But it is not coming like this. Please explain.

And when i use the above code as it is, i am getting error:
Quote:
# awk -F, '{ gsub("\"","") printf "%-7s\t%-18s\t%-10s\t%015.2f\n", $1, $2, $3, $4 }' inputfile.txt
Syntax Error The source line is 1.
The error context is
{ gsub("\"","") >>> printf <<< "%-7s\t%-18s\t%-10s\t%015.2f\n", $1, $2, $3, $4 }
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
Please correct me if i'm wrong anywhere.
# 4  
Old 12-11-2009
If you want the command on one line you have to separate the statements with a semicolon:

Code:
awk -F, '{ gsub("\"",""); printf "%-7s\t%-18s\t%-10s\t%015.2f\n", $1, $2, $3, $4 }' inputfile.txt
                        ^

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ps -ef, output getting truncated, please help

Hi All, here is an output of my command and the problem is that my output string is truncated, I want to exact the full string, I am on BASH shell, please help me out. Regards Rahul command with Output : lonss05903:cmdsvc01 /home/cmdsvc01 > ps -aef|grep 'Copy' cmdsvc01 2642 8675 ... (7 Replies)
Discussion started by: rahulkalra9
7 Replies

2. Solaris

ps output truncated

Hi, I have Solaris-10 server. /usr/ucb/ps auxww is showing full path if I am running it from root. But if I run it from non-root user, its output is truncated. I don't want to use any other alternate command. Please suggest, what can be its solution. Terminal is set to term. (21 Replies)
Discussion started by: solaris_1977
21 Replies

3. UNIX for Dummies Questions & Answers

Add leading zeros to columns in a file

Hello Gurus, Quick question. I have a file with the following records: A~000000000000518000~SLP ~99991231~20090701~88.50~USD~CS~ A~000000000000518000~SLP ~99991231~20090701~102.00~USD~CS~ A~000000000000772000~SLP ~99991231~20100701~118.08~USD~CS~ I wold like to do the following: 1. Add... (1 Reply)
Discussion started by: chumsky
1 Replies

4. Linux

relocation truncated to fit

Hi, I am getting linking error i.e. /ade/aime_urtk/oracle/has/include/caa_ResStateListener.hxx:79: relocation truncated to fit: R_PPC_GO T16 vtable for CAA::ResourceStateListener /ade/aime_urtk/oracle/has/lib//libcaad.a(caa_Main.o)(.text+0x88e6): In function `CAA::ResourceStateL... (0 Replies)
Discussion started by: jgobbur
0 Replies

5. UNIX for Dummies Questions & Answers

File gets truncated

Hi Guys, I have a master script file. That calls the other script files. The sub script files append some of the data to the log file. Once the master script completes one sub script execution and returns to execute other sub script that appends to the same log file. the log file gets... (2 Replies)
Discussion started by: Swapna173
2 Replies

6. Shell Programming and Scripting

Truncated with a pipe?

OK, I'm stumped. I have a shell script that reads a list, and for every item in the list performs a lookup in our Active Directory. Now, it seems that when I pipe the results into grep, the complete results are not there (truncated?). I'm not sure if this is a limit of the pipe, grep, shell... (1 Reply)
Discussion started by: TheCrunge
1 Replies

7. AIX

PS truncated in AIX

folks; how can i get longer output than the one i got by using "/usr/ucb/ps awwx"? :mad: (2 Replies)
Discussion started by: moe2266
2 Replies

8. Solaris

ps truncated output

Hi Problem of ps on Solaris 8 and 9 Perhaps a silly question but I can't find a solution. the output of the command ps -ef is truncated. I've tried to change the terminal settings with stty putting a big number of colums: no change. Following the man page of ps i have set the variable... (8 Replies)
Discussion started by: renoc
8 Replies

9. UNIX for Advanced & Expert Users

ps output truncated

Hi! I have some shell scripts receiving in input lots of parameters and I need to select the ones having a particular value in one parameter. A typical shell command line is: PROMPT > shell_name.ksh -avalue_a -bvalue_b -cvalue_c -dvalue_d ... I used a combinaton of ps and grep commands... (5 Replies)
Discussion started by: pciatto
5 Replies

10. Shell Programming and Scripting

ps output truncated

Hi! I have some shell scripts receiving in input lots of parameters and I need to select the ones having a particular value in one parameter. A typical shell command line is: PROMPT > shell_name.ksh -avalue_a -bvalue_b -cvalue_c -dvalue_d ... I used a combinaton of ps and grep commands... (1 Reply)
Discussion started by: pciatto
1 Replies
Login or Register to Ask a Question