|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Swapping column in vi editor
is there any command in vi editor to turn this Code:
986.000 4.026.000 775.328.625 9.319.003.000 986.000 4.036.000 775.328.625 9.318.803.000 986.000 4.046.000 775.328.625 9.318.603.000 986.000 4.056.000 775.328.625 9.318.403.000 become this Code:
4.026.000 986.000 775.328.625 9.319.003.000 4.036.000 986.000 775.328.625 9.318.803.000 4.046.000 986.000 775.328.625 9.318.603.000 4.056.000 986.000 775.328.625 9.318.403.000 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Hi Something like this: Code:
:%s/\([^ ]*\) *\([^ ]*\)/\2 \1 / Last edited by guruprasadpr; 11-19-2012 at 02:59 AM.. Reason: Removed g to prevent global substitution |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
:1,4s/\([^ \t]*\)\([ \t]*\)\([^ \t]*\)/\3\2\1/ Change the range 1,4 as per your requirements. |
|
#4
|
|||
|
|||
|
and in case you find the pure vi solution too complex, you might use awk this way: Code:
:%!awk '{t=$1;$1=$2;$2=t;print}'Last edited by jlliagre; 11-19-2012 at 03:16 AM.. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
@jlliagre,
I think you missed a 1 or print there. In any case, the spacing between the columns might get mangled. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks, I indeed missed a statement, post #4 fixed (I prefer 'print' to the cryptic '1'). Column separators will be normalized to a single space after running this command while your solution preserve the existing separators.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing 2nd Column in Vi Editor | muhnandap | UNIX for Dummies Questions & Answers | 9 | 09-27-2012 04:27 AM |
| Delete a specific column using vi editor? | fnebiolo | UNIX for Dummies Questions & Answers | 3 | 10-25-2010 03:28 AM |
| Vi editor, copy one column? | MeetP | Shell Programming and Scripting | 3 | 12-15-2009 01:45 PM |
| Swapping in VI editor | Jahn | UNIX for Dummies Questions & Answers | 1 | 06-24-2009 12:18 PM |
| VI editor,column postion | vijay_0209 | Shell Programming and Scripting | 1 | 10-29-2008 07:12 AM |
|
|