|
Home > Archive > Unix Shell > December 2006 > Swapping three columns in a file in VI editor..
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Swapping three columns in a file in VI editor..
|
|
|
| Hi ALL,
How to open three columns in a file without using
substitute command in vi editor?
Let us say file with the following contents,
//BOF
A1 B1 C1
A2 B2 C2
//EOF.
Then after swapping the file content should be,
//BOF
C1 A1 B1
C2 A2 B2
//EOF
Thanks in advance,
Regards,
sasi
| |
|
| Sorry there is small correction in my question. How to swap not open?
CKS wrote:
> Hi ALL,
> How to open three columns in a file without using
> substitute command in vi editor?
>
> Let us say file with the following contents,
>
> //BOF
>
> A1 B1 C1
>
> A2 B2 C2
>
> //EOF.
>
> Then after swapping the file content should be,
>
> //BOF
>
> C1 A1 B1
>
> C2 A2 B2
>
> //EOF
>
> Thanks in advance,
> Regards,
> sasi
| |
| Michael Tosch 2006-12-19, 7:32 am |
| CKS wrote:
> Hi ALL,
> How to swap three columns in a file without using
> substitute command in vi editor?
>
> Let us say file with the following contents,
>
> //BOF
>
> A1 B1 C1
>
> A2 B2 C2
>
> //EOF.
>
> Then after swapping the file content should be,
>
> //BOF
>
> C1 A1 B1
>
> C2 A2 B2
>
> //EOF
>
> Thanks in advance,
>
In a standard shell:
while read a b c
do
echo "$c $a $b"
done < oldfile > newfile
In vi, with the substitute command, it is harder,
and impossible otherwise.
--
Michael Tosch @ hp : com
| |
| Janis Papanagnou 2006-12-19, 7:32 am |
| Michael Tosch wrote:
> CKS wrote:
>
>
> In a standard shell:
>
> while read a b c
> do
> echo "$c $a $b"
> done < oldfile > newfile
>
> In vi, with the substitute command, it is harder,
> and impossible otherwise.
>
If the columns are aligned, though, you can do that with vim using
the "visual block" command <ctrl>-V.
Janis
| |
| Stephane CHAZELAS 2006-12-19, 7:32 am |
| 2006-12-18, 23:24(-08), CKS:
> Hi ALL,
> How to swap three columns in a file without using
> substitute command in vi editor?
>
> Let us say file with the following contents,
>
> //BOF
>
> A1 B1 C1
>
> A2 B2 C2
>
> //EOF.
>
> Then after swapping the file content should be,
>
> //BOF
>
> C1 A1 B1
>
> C2 A2 B2
>
> //EOF
[...]
:%!awk 'NF==3{$0=$3" "$1" "$2}{print}'
--
Stéphane
| |
| Stephane CHAZELAS 2006-12-19, 7:32 am |
| 2006-12-19, 10:44(+01), Michael Tosch:
[...]
> In a standard shell:
>
> while read a b c
> do
> echo "$c $a $b"
> done < oldfile > newfile
>
> In vi, with the substitute command, it is harder,
> and impossible otherwise.
[...]
???
vi can call sh. All vi implementations have macro support. Some
vi implementations have a builtin extension language. Some vi
implementations can even have a perl, Python or ruby interpretor
embedded. There's nothing a shell can do and vi can't.
Note that "echo" and "read" aren't the commands you think they
are.
--
Stéphane
|
|
|
|
|