Format Column Width with Printf

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am attempting to merge three files using 'paste' and 'awk'. However, the columns are not adjusting to the longest string of characters. All files are formatted in the same manner as below.



  • F gge0001x

  • D 12-30-2006

  • T 14:15:20

  • S a69

  • B 15.8

  • M gge06001

  • P 30.1

Below is my faulty code.



$ paste <(awk 'print $1' lineid) <
(awk 'printf("%-13.10sn", $1)' gge0001x) <
(awk 'printf("%-13.10sn", $1)' gge0001y) <
(awk 'printf("%-13.10sn", $1)' gge0001z)


This code results in misaligned columns as pictured below.
Misaligned Columns




Input File 1



F 
D
T
S
B
M
P
Q
R
U
X
A
G
H
O
C
K
W
L


Input File 2



gge0006x
12-30-2006
14:05:23
a69
15.4
gge06001
30.8
19.2
1006.2
1012.7
36.2
38.994
107.71
8.411
37.084
7.537
28.198
212.52
68.1


Input File 3



gge0006y
12-30-2006
14:05:55
a69
15.3
gge06001
30.6
21.1
1006.6
1014.6
36.1
38.994
107.71
8.433
36.705
7.621
27.623
210.51
68


Input File 4



gge0006z
12-30-2006
14:06:28
a69
15.7
gge06001
30.3
23.5
1008
1014.1
36.6
38.994
107.71
8.434
36.508
7.546
27.574
208.08
67.6



Results for paste file1 file2 file3 file4 | column -t
enter image description here










share|improve this question



















  • 1




    Can you please edit your post to include the input files you are using? This will greatly aid testing.
    – dhag
    Apr 21 '15 at 16:10










  • Sorry, I will do so right now.
    – M.Rubie
    Apr 21 '15 at 16:12






  • 1




    If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
    – steeldriver
    Apr 21 '15 at 16:37










  • Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
    – M.Rubie
    Apr 21 '15 at 16:44






  • 1




    I'm sorry. I didn't know.
    – M.Rubie
    Apr 21 '15 at 18:17














up vote
1
down vote

favorite












I am attempting to merge three files using 'paste' and 'awk'. However, the columns are not adjusting to the longest string of characters. All files are formatted in the same manner as below.



  • F gge0001x

  • D 12-30-2006

  • T 14:15:20

  • S a69

  • B 15.8

  • M gge06001

  • P 30.1

Below is my faulty code.



$ paste <(awk 'print $1' lineid) <
(awk 'printf("%-13.10sn", $1)' gge0001x) <
(awk 'printf("%-13.10sn", $1)' gge0001y) <
(awk 'printf("%-13.10sn", $1)' gge0001z)


This code results in misaligned columns as pictured below.
Misaligned Columns




Input File 1



F 
D
T
S
B
M
P
Q
R
U
X
A
G
H
O
C
K
W
L


Input File 2



gge0006x
12-30-2006
14:05:23
a69
15.4
gge06001
30.8
19.2
1006.2
1012.7
36.2
38.994
107.71
8.411
37.084
7.537
28.198
212.52
68.1


Input File 3



gge0006y
12-30-2006
14:05:55
a69
15.3
gge06001
30.6
21.1
1006.6
1014.6
36.1
38.994
107.71
8.433
36.705
7.621
27.623
210.51
68


Input File 4



gge0006z
12-30-2006
14:06:28
a69
15.7
gge06001
30.3
23.5
1008
1014.1
36.6
38.994
107.71
8.434
36.508
7.546
27.574
208.08
67.6



Results for paste file1 file2 file3 file4 | column -t
enter image description here










share|improve this question



















  • 1




    Can you please edit your post to include the input files you are using? This will greatly aid testing.
    – dhag
    Apr 21 '15 at 16:10










  • Sorry, I will do so right now.
    – M.Rubie
    Apr 21 '15 at 16:12






  • 1




    If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
    – steeldriver
    Apr 21 '15 at 16:37










  • Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
    – M.Rubie
    Apr 21 '15 at 16:44






  • 1




    I'm sorry. I didn't know.
    – M.Rubie
    Apr 21 '15 at 18:17












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am attempting to merge three files using 'paste' and 'awk'. However, the columns are not adjusting to the longest string of characters. All files are formatted in the same manner as below.



  • F gge0001x

  • D 12-30-2006

  • T 14:15:20

  • S a69

  • B 15.8

  • M gge06001

  • P 30.1

Below is my faulty code.



$ paste <(awk 'print $1' lineid) <
(awk 'printf("%-13.10sn", $1)' gge0001x) <
(awk 'printf("%-13.10sn", $1)' gge0001y) <
(awk 'printf("%-13.10sn", $1)' gge0001z)


This code results in misaligned columns as pictured below.
Misaligned Columns




Input File 1



F 
D
T
S
B
M
P
Q
R
U
X
A
G
H
O
C
K
W
L


Input File 2



gge0006x
12-30-2006
14:05:23
a69
15.4
gge06001
30.8
19.2
1006.2
1012.7
36.2
38.994
107.71
8.411
37.084
7.537
28.198
212.52
68.1


Input File 3



gge0006y
12-30-2006
14:05:55
a69
15.3
gge06001
30.6
21.1
1006.6
1014.6
36.1
38.994
107.71
8.433
36.705
7.621
27.623
210.51
68


Input File 4



gge0006z
12-30-2006
14:06:28
a69
15.7
gge06001
30.3
23.5
1008
1014.1
36.6
38.994
107.71
8.434
36.508
7.546
27.574
208.08
67.6



Results for paste file1 file2 file3 file4 | column -t
enter image description here










share|improve this question















I am attempting to merge three files using 'paste' and 'awk'. However, the columns are not adjusting to the longest string of characters. All files are formatted in the same manner as below.



  • F gge0001x

  • D 12-30-2006

  • T 14:15:20

  • S a69

  • B 15.8

  • M gge06001

  • P 30.1

Below is my faulty code.



$ paste <(awk 'print $1' lineid) <
(awk 'printf("%-13.10sn", $1)' gge0001x) <
(awk 'printf("%-13.10sn", $1)' gge0001y) <
(awk 'printf("%-13.10sn", $1)' gge0001z)


This code results in misaligned columns as pictured below.
Misaligned Columns




Input File 1



F 
D
T
S
B
M
P
Q
R
U
X
A
G
H
O
C
K
W
L


Input File 2



gge0006x
12-30-2006
14:05:23
a69
15.4
gge06001
30.8
19.2
1006.2
1012.7
36.2
38.994
107.71
8.411
37.084
7.537
28.198
212.52
68.1


Input File 3



gge0006y
12-30-2006
14:05:55
a69
15.3
gge06001
30.6
21.1
1006.6
1014.6
36.1
38.994
107.71
8.433
36.705
7.621
27.623
210.51
68


Input File 4



gge0006z
12-30-2006
14:06:28
a69
15.7
gge06001
30.3
23.5
1008
1014.1
36.6
38.994
107.71
8.434
36.508
7.546
27.574
208.08
67.6



Results for paste file1 file2 file3 file4 | column -t
enter image description here







bash awk printf paste






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 at 2:17









Rui F Ribeiro

38.2k1475123




38.2k1475123










asked Apr 21 '15 at 15:51









M.Rubie

83




83







  • 1




    Can you please edit your post to include the input files you are using? This will greatly aid testing.
    – dhag
    Apr 21 '15 at 16:10










  • Sorry, I will do so right now.
    – M.Rubie
    Apr 21 '15 at 16:12






  • 1




    If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
    – steeldriver
    Apr 21 '15 at 16:37










  • Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
    – M.Rubie
    Apr 21 '15 at 16:44






  • 1




    I'm sorry. I didn't know.
    – M.Rubie
    Apr 21 '15 at 18:17












  • 1




    Can you please edit your post to include the input files you are using? This will greatly aid testing.
    – dhag
    Apr 21 '15 at 16:10










  • Sorry, I will do so right now.
    – M.Rubie
    Apr 21 '15 at 16:12






  • 1




    If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
    – steeldriver
    Apr 21 '15 at 16:37










  • Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
    – M.Rubie
    Apr 21 '15 at 16:44






  • 1




    I'm sorry. I didn't know.
    – M.Rubie
    Apr 21 '15 at 18:17







1




1




Can you please edit your post to include the input files you are using? This will greatly aid testing.
– dhag
Apr 21 '15 at 16:10




Can you please edit your post to include the input files you are using? This will greatly aid testing.
– dhag
Apr 21 '15 at 16:10












Sorry, I will do so right now.
– M.Rubie
Apr 21 '15 at 16:12




Sorry, I will do so right now.
– M.Rubie
Apr 21 '15 at 16:12




1




1




If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
– steeldriver
Apr 21 '15 at 16:37




If you're just trying to format the output nicely have you considered using the column command instead of messing with the fields individually using awk? e.g. paste file1 file2 file3 file4 | column -t
– steeldriver
Apr 21 '15 at 16:37












Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
– M.Rubie
Apr 21 '15 at 16:44




Thank you, steeldriver. No luck either with that code. I edited my post with a screenshot using the suggested code.
– M.Rubie
Apr 21 '15 at 16:44




1




1




I'm sorry. I didn't know.
– M.Rubie
Apr 21 '15 at 18:17




I'm sorry. I didn't know.
– M.Rubie
Apr 21 '15 at 18:17










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










Your input files have DOS rn line endings. Remove the carriage returns with the dos2unix command or with sed -i 's/r$//'






share|improve this answer




















  • THANK YOU! I haven't slept all night. I would have never figured this out on my own.
    – M.Rubie
    Apr 21 '15 at 17:40

















up vote
0
down vote













The command paste separate entries with tabs, which are then interpreted as a variable number of spaces upon display. If your input is already padded with whitespace, you may try deleting tabs from the output of paste, with | tr -d 't', or turning each tab into a single space,with| tr 't' ' ' (on my system, the first can be achieved using paste -d '', but I don't know whether this is portable, and the second can be achieved with paste -d ' '; telling paste to use spaces as delimiters).






share|improve this answer




















  • Thank you, but I'm having no luck with either code you suggested.
    – M.Rubie
    Apr 21 '15 at 16:07










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f197663%2fformat-column-width-with-printf%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Your input files have DOS rn line endings. Remove the carriage returns with the dos2unix command or with sed -i 's/r$//'






share|improve this answer




















  • THANK YOU! I haven't slept all night. I would have never figured this out on my own.
    – M.Rubie
    Apr 21 '15 at 17:40














up vote
2
down vote



accepted










Your input files have DOS rn line endings. Remove the carriage returns with the dos2unix command or with sed -i 's/r$//'






share|improve this answer




















  • THANK YOU! I haven't slept all night. I would have never figured this out on my own.
    – M.Rubie
    Apr 21 '15 at 17:40












up vote
2
down vote



accepted







up vote
2
down vote



accepted






Your input files have DOS rn line endings. Remove the carriage returns with the dos2unix command or with sed -i 's/r$//'






share|improve this answer












Your input files have DOS rn line endings. Remove the carriage returns with the dos2unix command or with sed -i 's/r$//'







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 21 '15 at 17:19









glenn jackman

49.3k469106




49.3k469106











  • THANK YOU! I haven't slept all night. I would have never figured this out on my own.
    – M.Rubie
    Apr 21 '15 at 17:40
















  • THANK YOU! I haven't slept all night. I would have never figured this out on my own.
    – M.Rubie
    Apr 21 '15 at 17:40















THANK YOU! I haven't slept all night. I would have never figured this out on my own.
– M.Rubie
Apr 21 '15 at 17:40




THANK YOU! I haven't slept all night. I would have never figured this out on my own.
– M.Rubie
Apr 21 '15 at 17:40












up vote
0
down vote













The command paste separate entries with tabs, which are then interpreted as a variable number of spaces upon display. If your input is already padded with whitespace, you may try deleting tabs from the output of paste, with | tr -d 't', or turning each tab into a single space,with| tr 't' ' ' (on my system, the first can be achieved using paste -d '', but I don't know whether this is portable, and the second can be achieved with paste -d ' '; telling paste to use spaces as delimiters).






share|improve this answer




















  • Thank you, but I'm having no luck with either code you suggested.
    – M.Rubie
    Apr 21 '15 at 16:07














up vote
0
down vote













The command paste separate entries with tabs, which are then interpreted as a variable number of spaces upon display. If your input is already padded with whitespace, you may try deleting tabs from the output of paste, with | tr -d 't', or turning each tab into a single space,with| tr 't' ' ' (on my system, the first can be achieved using paste -d '', but I don't know whether this is portable, and the second can be achieved with paste -d ' '; telling paste to use spaces as delimiters).






share|improve this answer




















  • Thank you, but I'm having no luck with either code you suggested.
    – M.Rubie
    Apr 21 '15 at 16:07












up vote
0
down vote










up vote
0
down vote









The command paste separate entries with tabs, which are then interpreted as a variable number of spaces upon display. If your input is already padded with whitespace, you may try deleting tabs from the output of paste, with | tr -d 't', or turning each tab into a single space,with| tr 't' ' ' (on my system, the first can be achieved using paste -d '', but I don't know whether this is portable, and the second can be achieved with paste -d ' '; telling paste to use spaces as delimiters).






share|improve this answer












The command paste separate entries with tabs, which are then interpreted as a variable number of spaces upon display. If your input is already padded with whitespace, you may try deleting tabs from the output of paste, with | tr -d 't', or turning each tab into a single space,with| tr 't' ' ' (on my system, the first can be achieved using paste -d '', but I don't know whether this is portable, and the second can be achieved with paste -d ' '; telling paste to use spaces as delimiters).







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 21 '15 at 16:00









dhag

11k32942




11k32942











  • Thank you, but I'm having no luck with either code you suggested.
    – M.Rubie
    Apr 21 '15 at 16:07
















  • Thank you, but I'm having no luck with either code you suggested.
    – M.Rubie
    Apr 21 '15 at 16:07















Thank you, but I'm having no luck with either code you suggested.
– M.Rubie
Apr 21 '15 at 16:07




Thank you, but I'm having no luck with either code you suggested.
– M.Rubie
Apr 21 '15 at 16:07

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f197663%2fformat-column-width-with-printf%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?