• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

VI - how to replace arbitary column(s)

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
Nick Upson
Asked:
Nick Upson
  • 2
1 Solution
 
tfewsterCommented:
:1,$s/^\(....\)X/\1Y/
0
 
tfewsterCommented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now