Format Column Width with Printf
Clash 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.
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
bash awk printf paste
|
show 1 more comment
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.
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
bash awk printf paste
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 thecolumn
command instead of messing with the fields individually usingawk
? 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
|
show 1 more comment
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.
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
bash awk printf paste
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.
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
bash awk printf paste
bash awk printf paste
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 thecolumn
command instead of messing with the fields individually usingawk
? 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
|
show 1 more comment
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 thecolumn
command instead of messing with the fields individually usingawk
? 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
|
show 1 more comment
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$//'
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
add a comment |
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).
Thank you, but I'm having no luck with either code you suggested.
– M.Rubie
Apr 21 '15 at 16:07
add a comment |
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$//'
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
add a comment |
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$//'
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
add a comment |
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$//'
Your input files have DOS rn
line endings. Remove the carriage returns with the dos2unix
command or with sed -i 's/r$//'
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
add a comment |
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
add a comment |
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).
Thank you, but I'm having no luck with either code you suggested.
– M.Rubie
Apr 21 '15 at 16:07
add a comment |
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).
Thank you, but I'm having no luck with either code you suggested.
– M.Rubie
Apr 21 '15 at 16:07
add a comment |
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).
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).
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usingawk
? 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