Solved

VI - how to replace arbitary column(s)

Posted on 2004-10-05
2
565 Views
Last Modified: 2010-04-21
I've used vi and unix for years but I've never found a good way to do this.

I want to search and replace based on column/character number

the search part I can do by

/^......<correct number of .>...X/

given its an 'X' in the column I want but I can't do

:1,$s/^.............................X/.....................Y/

unless I want all .'s in the file
0
Comment
Question by:NickUpson
  • 2
2 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 12226932
:1,$s/^\(....\)X/\1Y/
0
 
LVL 20

Accepted Solution

by:
tfewster earned 500 total points
ID: 12226966
The way I understand this is:
Look for X in the 5th column;  "Remember" the characters in the columns 1-4 (4 .'s) in a sed variable.
Subsitute the "pattern" found with \1Y, where \1 is the contents of the variable
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now