Search code examples
bashsed

Move a column using sed


My Awk script generates this output:

1396.0893854748604 jdbc:mysql 192.168.0.8:3306/ycsb 3

I need to put the final column at the start, but do not wish to swap its position with the first. I need to do this using sed, or another pipe that is not awk.

I have tried variants of this command, but with no luck. My output just stays the same.

sed 's@\(.*\),\(.*\),\(.*\)@\4,\1,\2,\3@g' 

Just for clarity my desired output would look like this:

3 1396.0893854748604 jdbc:mysql 192.168.0.8:3306/ycsb 

Solution

  • You should use awk for this. It's better:

    awk '{print $4, $1, $2, $3}' yourfilename
    

    Updated: Oh right... Now I see that you require not using awk again... that's a wierd requirement. Leaving this here because it may be useful for future visitors.