You can modify the characters at a particular index within a line like this:
Code:
bob@cob:~$ cat /tmp/file
name = john
surname = smith
tall = 187.12 cm
age = 34
bob@cob:~$ perl -pe 'if($.=="3"){substr($_,7,6,"ABCDEF");} ' /tmp/file
name = john
surname = smith
tall = ABCDEF cm
age = 34
Some explanation:
The variable named $. is the current line number.
The substr() function takes the following arguments:
substr EXPR,OFFSET,LENGTH,REPLACEMENT
For more information, run "perldoc -f substr"
Perl's "-p" flag iterates through each line in the given input file, running the given code before printing the line.
The variable named "$_" holds the contents of the current line.
Bookmarks