Preformat output CSV
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I have a script bash that converts this file "origin.txt"
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
to
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
How could I do it in bash with AWK?
linux awk sed text-formatting
add a comment |Â
up vote
4
down vote
favorite
I have a script bash that converts this file "origin.txt"
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
to
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
How could I do it in bash with AWK?
linux awk sed text-formatting
3
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something likepaste -d, - - - < origin.txt
or (if you insist on awk)awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have a script bash that converts this file "origin.txt"
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
to
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
How could I do it in bash with AWK?
linux awk sed text-formatting
I have a script bash that converts this file "origin.txt"
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
to
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
How could I do it in bash with AWK?
linux awk sed text-formatting
edited Aug 6 at 17:08
SivaPrasath
3,68311636
3,68311636
asked Aug 6 at 15:15
kdetony
211
211
3
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something likepaste -d, - - - < origin.txt
or (if you insist on awk)awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56
add a comment |Â
3
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something likepaste -d, - - - < origin.txt
or (if you insist on awk)awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56
3
3
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like
paste -d, - - - < origin.txt
or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like
paste -d, - - - < origin.txt
or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
Using sed:
sed 'N;N;s/n/,/g' origin.txt
Using awk:
awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt
Output:
cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z
add a comment |Â
up vote
3
down vote
I have an awk script file named tmp.awk
with the following contents
BEGIN
i=0
if (i==0)
f1=$0
i++
else if (i==1)
f2=$0
i++
else
i=0
print f1","f2","$0
And a file origin.txt
with the following contents
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
Here is my awk command and sample output.
zb@server ~ $ awk -f tmp.awk origin.txt
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Using sed:
sed 'N;N;s/n/,/g' origin.txt
Using awk:
awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt
Output:
cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z
add a comment |Â
up vote
4
down vote
Using sed:
sed 'N;N;s/n/,/g' origin.txt
Using awk:
awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt
Output:
cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Using sed:
sed 'N;N;s/n/,/g' origin.txt
Using awk:
awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt
Output:
cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z
Using sed:
sed 'N;N;s/n/,/g' origin.txt
Using awk:
awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt
Output:
cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z
answered Aug 6 at 17:04
SivaPrasath
3,68311636
3,68311636
add a comment |Â
add a comment |Â
up vote
3
down vote
I have an awk script file named tmp.awk
with the following contents
BEGIN
i=0
if (i==0)
f1=$0
i++
else if (i==1)
f2=$0
i++
else
i=0
print f1","f2","$0
And a file origin.txt
with the following contents
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
Here is my awk command and sample output.
zb@server ~ $ awk -f tmp.awk origin.txt
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
add a comment |Â
up vote
3
down vote
I have an awk script file named tmp.awk
with the following contents
BEGIN
i=0
if (i==0)
f1=$0
i++
else if (i==1)
f2=$0
i++
else
i=0
print f1","f2","$0
And a file origin.txt
with the following contents
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
Here is my awk command and sample output.
zb@server ~ $ awk -f tmp.awk origin.txt
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
I have an awk script file named tmp.awk
with the following contents
BEGIN
i=0
if (i==0)
f1=$0
i++
else if (i==1)
f2=$0
i++
else
i=0
print f1","f2","$0
And a file origin.txt
with the following contents
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
Here is my awk command and sample output.
zb@server ~ $ awk -f tmp.awk origin.txt
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
I have an awk script file named tmp.awk
with the following contents
BEGIN
i=0
if (i==0)
f1=$0
i++
else if (i==1)
f2=$0
i++
else
i=0
print f1","f2","$0
And a file origin.txt
with the following contents
cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z
Here is my awk command and sample output.
zb@server ~ $ awk -f tmp.awk origin.txt
cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z
answered Aug 6 at 16:37
Zachary Brady
3,376831
3,376831
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
add a comment |Â
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
thank you very much they gave me several ideas with their eternally grateful examples
â kdetony
2 days ago
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460845%2fpreformat-output-csv%23new-answer', 'question_page');
);
Post as a guest
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
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
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
3
So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like
paste -d, - - - < origin.txt
or (if you insist on awk)awk 'ORS="n" NR%3 ORS="," 1' origin.txt
â steeldriver
Aug 6 at 16:56