?
Solved

VI - how to replace arbitary column(s)

Posted on 2004-10-05
2
Medium Priority
?
601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 21

Expert Comment

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

Accepted Solution

by:
tfewster earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

719 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