views:

392

answers:

5

Hi,

So I have this big file of fix length lines. I want to do a find and replace on a character line position.

Example:

xxxxxxx     010109 xxxxxx xxxxx
xxxxxxx     010309 xxxxxx xxxxx
xxxxxxx     021506 xxxxxx xxxxx
xxxxxxx     041187 xxxxxx xxxxx

So in this case I would want to find any value starting on position 13 through position 18 and replace it with 010107.

Can anyone give help me out on how to formulate the regex for this?

Much appreciated.

A: 

Try this search pattern:

^(.{12})\d{6}

And this as replacement expression:

\1010107
Gumbo
+1  A: 

Edited: after testing, Notepad++ doesn't support the {n} method of defining an exact number of chars

This works, tested on your data:

Find:

^(............)......

Replace:

\1010107
Chad Birch
+1 for making it work in Notepad++.
Grant Wagner
Thanks I think I this can work.
homerjay
A: 

s/^(?:.{12})(.{6})(?:.*)$/NNNNNN/

replacing NNNNNN by the desired number

qux
A: 

Something like this:

sed 's/^\(.\{12\}\).\{6\}\(.*\)$/\1010107\2/'

should do the trick (escaped for command line use)

simon
A: 

Just for the record, you don't need a regular expression for something like this. A simple split, or some kind of unpack function, would be just fine.

AmbroseChapel