I have a file(Pipe Delimited) where i need to add a blank field before the last field and a blank field after the last field. Please help. I have provided below the sample input records and desired output.
Sample Input:
A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West|US HEADQUARTERS
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central|US HEADQUARTERS
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West|US HEADQUARTERS
Sample Output Required:
A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West||US HEADQUARTERS|
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central||US HEADQUARTERS|
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West||US HEADQUARTERS|
Sorry about the Subject not being descriptive. And thanks very much for the reply i was testing the code with my file and it really works fine. Just wanted to know if awk is fastest or we do have any other utility which is faster than awk as i am dealing with millions of records.
It's OK. Just try to use a subject title that you yourself would type into a search engine and expect to find an answer.
I don't know what would be fastest. You could try sed
$ sed "s/|[^|]*$/|&|/" file
A0010000|Abilene TX A 1|A0010957|Dallas TX|A0010998|West||US HEADQUARTERS|
A0010001|Akron OH A 1|A0010954|Cleveland OH|A0010997|Central||US HEADQUARTERS|
A0010002|Alaska AK A 1|A0010991|Seattle WA|A0010998|West||US HEADQUARTERS|
Thanks for the reply @scrutinizer but your code only adds blank field before the last field. i needed to add before and after. i can modify it and it can work but takes the same time.
---------- Post updated at 04:34 PM ---------- Previous update was at 04:32 PM ----------