Change format and align the count
Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
I want to change the format
From:
Sample.txt
Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan
To:
Output.txt
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3
aix text-formatting
 |Â
show 1 more comment
up vote
-2
down vote
favorite
I want to change the format
From:
Sample.txt
Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan
To:
Output.txt
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3
aix text-formatting
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42
 |Â
show 1 more comment
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I want to change the format
From:
Sample.txt
Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan
To:
Output.txt
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3
aix text-formatting
I want to change the format
From:
Sample.txt
Count Data
1 C0263/Pre-approved Auto Load BC
1 C0263/Pre-approved Auto Load BC Holders
3 C0268/Pre-approved Auto Loan
To:
Output.txt
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto BC Holders 1
C0268/Pre-approved Auto Loan 3
aix text-formatting
edited Nov 6 '17 at 11:43
asked Nov 6 '17 at 10:41
John Christian Dela Cruz
215
215
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42
 |Â
show 1 more comment
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
awk solution:
awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt
The output:
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output ofawk --version
(as was asked) ?
â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
add a comment |Â
up vote
0
down vote
Assuming the input data is in the file datafile.txt
and you are using a POSIX shell, you can say
sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done
The sed
command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while
loop which reads two fields separated by a colon then prints them nicely.
If the input data comes from a pipe then delete the datafile.txt
argument and pipe it into sed
.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
awk solution:
awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt
The output:
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output ofawk --version
(as was asked) ?
â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
add a comment |Â
up vote
1
down vote
accepted
awk solution:
awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt
The output:
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output ofawk --version
(as was asked) ?
â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
awk solution:
awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt
The output:
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3
awk solution:
awk 'NR==1 printf "%4s%-44s%sn",FS,$2,$1; next
f1=$1; sub(/^ *[^ ]+ */,""); printf "%4s%-44s%sn",FS,$0,f1 ' Sample.txt
The output:
Data Count
C0263/Pre-approved Auto Load BC 1
C0263/Pre-approved Auto Load BC Holders 1
C0268/Pre-approved Auto Loan 3
answered Nov 6 '17 at 11:56
RomanPerekhrest
22.5k12145
22.5k12145
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output ofawk --version
(as was asked) ?
â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
add a comment |Â
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output ofawk --version
(as was asked) ?
â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
It doesnâÂÂt work sir
â John Christian Dela Cruz
Nov 6 '17 at 13:41
@JohnChristianDelaCruz, why did not you post the output of
awk --version
(as was asked) ?â RomanPerekhrest
Nov 6 '17 at 14:04
@JohnChristianDelaCruz, why did not you post the output of
awk --version
(as was asked) ?â RomanPerekhrest
Nov 6 '17 at 14:04
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
When applying the script you gave, the output is C0263/Pre-approved only
â John Christian Dela Cruz
Nov 6 '17 at 14:38
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
@JohnChristianDelaCruz, now, you got my screenshot ibb.co/g3ieaw
â RomanPerekhrest
Nov 6 '17 at 14:55
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
it works! Thanks a lot sir!
â John Christian Dela Cruz
Nov 7 '17 at 1:47
add a comment |Â
up vote
0
down vote
Assuming the input data is in the file datafile.txt
and you are using a POSIX shell, you can say
sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done
The sed
command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while
loop which reads two fields separated by a colon then prints them nicely.
If the input data comes from a pipe then delete the datafile.txt
argument and pipe it into sed
.
add a comment |Â
up vote
0
down vote
Assuming the input data is in the file datafile.txt
and you are using a POSIX shell, you can say
sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done
The sed
command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while
loop which reads two fields separated by a colon then prints them nicely.
If the input data comes from a pipe then delete the datafile.txt
argument and pipe it into sed
.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Assuming the input data is in the file datafile.txt
and you are using a POSIX shell, you can say
sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done
The sed
command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while
loop which reads two fields separated by a colon then prints them nicely.
If the input data comes from a pipe then delete the datafile.txt
argument and pipe it into sed
.
Assuming the input data is in the file datafile.txt
and you are using a POSIX shell, you can say
sed -e 's/^s*//' -e 's/s+/:/' datafile.txt | while IFS=':' read a b; do
printf '%-30.29s%sn' "$b" "$a"
done
The sed
command will (1) delete any leading spaces, then (2) replace the first occurrence of one or more spaces with a colon; the result is piped to a while
loop which reads two fields separated by a colon then prints them nicely.
If the input data comes from a pipe then delete the datafile.txt
argument and pipe it into sed
.
answered Nov 6 '17 at 11:49
AlexP
6,656924
6,656924
add a comment |Â
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%2f402805%2fchange-format-and-align-the-count%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
So you want to change the format. That's a perfectly reasonable desire. Why don't you change it?
â AlexP
Nov 6 '17 at 11:18
IsnâÂÂt that what Questions are for, @AlexP?
â Jeff Schaller
Nov 6 '17 at 11:32
are there a whitespaces at the begining of each line?
â RomanPerekhrest
Nov 6 '17 at 11:36
@JeffSchaller: What question? The original post simply declares that the poster wants to do something. They did not try anything, they did not run into any difficulties.
â AlexP
Nov 6 '17 at 11:38
Yes sir @RomanPerekhrest
â John Christian Dela Cruz
Nov 6 '17 at 11:42