replace specific position with sed
Hi.
i need to overwrite each line of the file starting from a specific position to the end of the line example: ATOM 981 N PRO B 159 55.662 7 1 1.47 0.75 i need to write " 1.00 0.00 " starting from 20position i tried sed -i 's/^\(.\{20\}\)*/\ 1.00 0.00 ' filename but it doesnt work :"( i'd appreciate your help |
Option -r of sed let you write extended regular expressions without escaping special character, so that your line is more readable and less prone to errors. By the way, you missed a dot before the asterisk, to match the rest of the string after the 20th position. Furthermore, if you want to start overwriting from the 20th position you need to retain only the first 19 characters, as in:
Code:
sed -r 's/^(.{19}).*/\1 1.00 0.00 /' file |
thank you very much, it works!!!!!!!!!!!!!!!!!!!
|
You're welcome! :)
|
Please mark as SOLVED once you have a working solution :)
|
I would like to replace 'xxxx' with 'yyyy' which is in a file xyz.csproj
not sure of what 'xxxx' is, it can be 3055, 4056, 7089 etc. I know it always appears at line # 5 and at character 50. <Reference Include="System.Management" /> <Reference Include="System.ServiceProcess" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> <Reference Include="Utilities, Version=4.4.0.xxxx, Culture=neutral, PublicKeyToken=c944cec9fb0a3d4a, processorArchitecture=x86" /> Any help is highly appreciated. |
...and if I need to keep even the characters in the previous 20?
thx |
All times are GMT -5. The time now is 07:55 AM. |