John Roberts 324-141-984 Acct
Jack Williams 159-555-555 Acct
William Jackson 949-911-888 Acct
Mark J Walton 145-852-252 Acct
Fred P Milton 483-244-390 Acct
Bill P J Miller 404-050-223 Acct
into this: Using AWK (Equal distance between columns)
John Roberts 324-141-984 Acct
Jack Williams 159-555-555 Acct
William Jackson 949-911-888 Acct
Mark J Walton 145-852-252 Acct
Fred P Milton 483-244-390 Acct
Bill P J Miller 404-050-223 Acct
As you can see the names are 2,3,4 fields long.
Here is my code but it is not working because the Names column is messing the other columns:
It's a bit tricky if you don't know how many fields there are and you use whitespace (spaces and tabs) to separate them (unless you use 1 tab to separate the fields, in which cast you could say:
John Roberts|324-141-984|Acct
Jack Williams|159-555-555|Acct
William Jackson|949-911-888|Acct
Mark J Walton|145-852-252|Acct
Fred P Milton|483-244-390|Acct
Bill P J Miller|404-050-223|Acct
and then use
awk -F"|" ....
That way the full name is always $1, the number $2 and Acct $3
If you think the number of fields may be more then give that example.
You have to know the data structure and the fields.
I cannot give a solution for some thing I dont know about.
I can change you data to this.
John Roberts|324-141-984|Acct
Jack Williams|159-555-555|Acct
William Jackson|949-911-888|Acct
Mark J Walton|145-852-252|Acct
Fred P Milton|483-244-390|Acct
Bill P J Miller|404-050-223|Acct
I dont see any thing wrong with Danmero's solution. I fact I think it might be more flexible and goingforth that might give the solution than mine.
Right now itisnotthebest.
Try this:
The 2nd solution of danmero meet the needs of what the OP wants (check the first post). This is what I get:
$ cat file
John Roberts 324-141-984 Acct
Jack Williams 159-555-555 Acct
William Jackson 949-911-888 Acct
Mark J Walton 145-852-252 Acct
Fred P Milton 483-244-390 Acct
Bill P J Miller 404-050-223 Acct
$
$ awk '{a=$(NF-1);b=$NF;$(NF-1)=$NF="";printf "%s%20s%10s\n",$0,a,b}' file
John Roberts 324-141-984 Acct
Jack Williams 159-555-555 Acct
William Jackson 949-911-888 Acct
Mark J Walton 145-852-252 Acct
Fred P Milton 483-244-390 Acct
Bill P J Miller 404-050-223 Acct