I have two solutions.
ANSWER ONE: Use sed 3 times to do the following:
- start with the original line: 12345678
- duplicate the first two parameters: 1212345678
- chop the 4th parameter: 121345678
- chop the 1st parameter: 21345678
Here's the resultant command using sed (Using XXX and YYY as helpers to find and remove the 1st and 4th parameters):
sed 's/["][^"]*["][^"]*["][^"]*["]/XXX& & YYY/' data.txt | sed 's/["][^"]*["] YYY//' | sed 's/XXX["][^"]*["]//'
ANSWER TWO: Convert data into a script and run it!
- convert the data.txt into a data.sh by inserting a command (say flipcol.sh)
- run the data.sh
Implement flipcol.sh as:
echo '"'$2'"' '"'$1'"' '"'$3'"' '"'$4'"' '"'$5'"' '"'$6'"' '"'$7'"' '"'$8'"'
Then run the following command on your data.txt creating a shell script:
sed 's!^!./flipcol.sh !' < data.txt > data.sh
Then run the newly created shell script
./data.sh