Moving the last six digits to the beginning of numbers
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?
I have tried googling it but all the examples given assume each line has the same number of fields
example:
76356378090986
08976357627980089
089723571237809209
0897253712730912838798
908916523568909887
876756467890
09876535467890
765643324343
467890876543
234567890987654
123456789009876543
54323456789876
09876543345678
123456789009876
12345678998765
result:
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
text-processing awk
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?
I have tried googling it but all the examples given assume each line has the same number of fields
example:
76356378090986
08976357627980089
089723571237809209
0897253712730912838798
908916523568909887
876756467890
09876535467890
765643324343
467890876543
234567890987654
123456789009876543
54323456789876
09876543345678
123456789009876
12345678998765
result:
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
text-processing awk
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?
I have tried googling it but all the examples given assume each line has the same number of fields
example:
76356378090986
08976357627980089
089723571237809209
0897253712730912838798
908916523568909887
876756467890
09876535467890
765643324343
467890876543
234567890987654
123456789009876543
54323456789876
09876543345678
123456789009876
12345678998765
result:
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
text-processing awk
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am using Twitter to pull news into an email, and the last six fields are the date and time. I would like these to be the first six fields. What's the command in awk to move the last n fields to the start of the line?
I have tried googling it but all the examples given assume each line has the same number of fields
example:
76356378090986
08976357627980089
089723571237809209
0897253712730912838798
908916523568909887
876756467890
09876535467890
765643324343
467890876543
234567890987654
123456789009876543
54323456789876
09876543345678
123456789009876
12345678998765
result:
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
text-processing awk
text-processing awk
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 13 mins ago
Rui F Ribeiro
37k1273117
37k1273117
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 27 mins ago
marco
1204
1204
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marco is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
With sed
:
sed 's/(.*)(.6)/21/'
sooooooo elegant ;-)
– Goro
18 mins ago
add a comment |Â
up vote
1
down vote
cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
add a comment |Â
up vote
0
down vote
With sed:
sed 's/(.*)(.6)/21/'
Or:
sed -E 's/(.*)(.6)/21/'
With (GNU) awk:
awk 'print gensub(/(.*)(.6)/,"21",1)'
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
With sed
:
sed 's/(.*)(.6)/21/'
sooooooo elegant ;-)
– Goro
18 mins ago
add a comment |Â
up vote
3
down vote
With sed
:
sed 's/(.*)(.6)/21/'
sooooooo elegant ;-)
– Goro
18 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
With sed
:
sed 's/(.*)(.6)/21/'
With sed
:
sed 's/(.*)(.6)/21/'
answered 19 mins ago


Stéphane Chazelas
287k53531868
287k53531868
sooooooo elegant ;-)
– Goro
18 mins ago
add a comment |Â
sooooooo elegant ;-)
– Goro
18 mins ago
sooooooo elegant ;-)
– Goro
18 mins ago
sooooooo elegant ;-)
– Goro
18 mins ago
add a comment |Â
up vote
1
down vote
cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
add a comment |Â
up vote
1
down vote
cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
cat file | sed -e 's/(.)/1 /g' | awk ' for (i = 1; i <= NF; i++) printf "%s" FS, $((NF-7+i) % NF+1); print ""' | sed 's/ //g'
09098676356378
98008908976357627
809209089723571237
8387980897253712730912
909887908916523568
467890876756
46789009876535
324343765643
876543467890
987654234567890
876543123456789009
78987654323456
34567809876543
009876123456789
99876512345678
answered 19 mins ago
Goro
7,45253169
7,45253169
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
add a comment |Â
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
that's a clear example of [Humor] Useless use of cat. sed is able to read a file. Having used awk, why also call sed (twice)?
– Isaac
2 mins ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
@Isaac thank you for sharing. It is the idea, the first sed created spaces between digits and the last sed removed them , it is an idea and still valied regardless if whether it is reckless or not ;-)
– Goro
43 secs ago
add a comment |Â
up vote
0
down vote
With sed:
sed 's/(.*)(.6)/21/'
Or:
sed -E 's/(.*)(.6)/21/'
With (GNU) awk:
awk 'print gensub(/(.*)(.6)/,"21",1)'
add a comment |Â
up vote
0
down vote
With sed:
sed 's/(.*)(.6)/21/'
Or:
sed -E 's/(.*)(.6)/21/'
With (GNU) awk:
awk 'print gensub(/(.*)(.6)/,"21",1)'
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With sed:
sed 's/(.*)(.6)/21/'
Or:
sed -E 's/(.*)(.6)/21/'
With (GNU) awk:
awk 'print gensub(/(.*)(.6)/,"21",1)'
With sed:
sed 's/(.*)(.6)/21/'
Or:
sed -E 's/(.*)(.6)/21/'
With (GNU) awk:
awk 'print gensub(/(.*)(.6)/,"21",1)'
answered 6 mins ago


Isaac
7,73711137
7,73711137
add a comment |Â
add a comment |Â
marco is a new contributor. Be nice, and check out our Code of Conduct.
marco is a new contributor. Be nice, and check out our Code of Conduct.
marco is a new contributor. Be nice, and check out our Code of Conduct.
marco is a new contributor. Be nice, and check out our Code of Conduct.
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%2f473964%2fmoving-the-last-six-digits-to-the-beginning-of-numbers%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