Quote:
Thanks for the answer Don, but your solution assumes fixed number of spaces. So it does not work.
But the file i have does not have a constant number of blank spaces between the columns..
I definitely learned that the output is stored int \1, \2 and \3. this is good info.
Now I am completely confused. Please show me an input line where the suggestion I made worked incorrectly due to the number of spaces between fields!
The BRE
[^[:space:]]*[[:space:]]* matches any number of characters that are not in the space character class followed by any number of characters that are in the space character class (for the purposes of this discussion, the space character class contains the characters <space>, <form-feed>, <carriage-return>, <tab>, and <vertical-tab>). My solution assumes a fixed number of fields to be processed; not a fixed number of spaces between fields.
The only constant number of spaces in what I provided is that when I moved field 7 to the start of the line, I added a single <space> after the moved field (which matched what you did in your sample). (I originally wrote it to move the spaces following field 7 in the input to be the separator between moved field and the original 1st field on the line. I went to a single space when I saw that it didn't match what you said you wanted.)
You may also note that your data samples did not always have the same number of spaces between fields in the input and output.
-------------------
The only thing that required a fixed number of spaces was the
cut example you provided that you said could be used to do what you wanted. I was just pointing out that
cut will not work for this problem because you don't have a fixed number of spaces.