Re: Insert character x at...
Aurelio Jargas <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <CABMdp-FPn7JjpLn-jwdXaBMj6Z4Cu+aN9PJ97SyMH-xeKxACuA@mail.gmail.com> |
On Thursday, May 16, 2013, Tim Chase wrote:
> On 2013-05-14 21:17, blackmuerte wrote:
> > For every line in input file that begins with '0530' (in first 4
> > characters on line), insert 'x' at position/column 32 on same line,
> > then output the whole file to a newfile.
>
> For the original request:
>
> sed '/^0530/s/\(.\{31\}/\1x/' input.txt
>
One alternative to insert a char after a column N is to use the numeric
flag in the s command.
$ echo 123456789 | sed 's/./&x/5'
12345x6789
Substitute any char (.) by itself (&) and an x. But only in the 5th
occurrence.
--
Aurelio | www.aurelio.net | @oreio
[Non-text portions of this message have been removed]