have the same column L

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

have the same column L

Krem
Hi all,

How can I starndarzied string column to have the same column length for each row.

Example
filename

A135953
D10036050
C135858000

I want add leading zeros and the column length should be 10

I tried
awk '{ printf "%010s \n", $1}' filename

Got all zeros
0000000000
0000000000
0000000000
0000000000

But I want
000A135953
0D10036050
C135858000


I would appreciate if you help me out.

thank you in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: have the same column L

PePa
Assuming the input is hexadecimal, a function like this would format
each line as intended:

   formatline() { printf "%010X \n";}

Then a line like this would give the intended result:

   while read -r; do fl $REPLY; done <filename

Of course, many assumptions and no error checking here...

Cheers,
Peter


On 07/14/2017 08:29 AM, Krem wrote:

> Hi all,
>
> How can I starndarzied string column to have the same column length for each row.
>
> Example
> filename
>
> A135953
> D10036050
> C135858000
>
> I want add leading zeros and the column length should be 10
>
> I tried
> awk '{ printf "%010s \n", $1}' filename
>
> Got all zeros
> 0000000000
> 0000000000
> 0000000000
> 0000000000
>
> But I want
> 000A135953
> 0D10036050
> C135858000
>
>
> I would appreciate if you help me out.
>
> thank you in advance
>
>
>
>
> --
> View this message in context: http://gnu-bash.2382.n7.nabble.com/have-the-same-column-L-tp19574.html
> Sent from the Gnu - Bash mailing list archive at Nabble.com.
>

Loading...