I want to add time stamp inside the file only after matching specific string:
timestamp format: 03_2016
file contains "$channel_name Policy" string, I want to replace this string with "$channel_name Policy_03_2016"
content of file which I want to add timestamp:
package_path=/LSB/Packages/Policy
channel_path=/LSB/Channels/$parent_channel_name/$channel_name Policy
erratum_path=/LSB/Errata/$erratum_type Policies/$erratum_name
errata_path =/LSB/Errata/$parent_channel_name/$channel_name Advisory Roll-Up Policy
package_path=/LSB/Packages/Unapproved/$channel_name
Required file format:
package_path=/LSB/Packages/Policy
channel_path=/LSB/Channels/$parent_channel_name/$channel_name Policy_03_2016
erratum_path=/LSB/Errata/$erratum_type Policies/$erratum_name
errata_path =/LSB/Errata/$parent_channel_name/$channel_name Advisory Roll-Up Policy
package_path=/LSB/Packages/Unapproved/$channel_name
Right now I'm using following command to add timestamp to file:
sed -i "s/$channel_name Policy/$channel_name Policy_$(date +%m_%Y)/g" filename
but this command is replacing all occurrences of Policy with Policy_03_2016 like this:
package_path=/LSB/Packages/Policy_03_2016
channel_path=/LSB/Channels/$parent_channel_name/$channel_name Policy_03_2016
erratum_path=/LSB/Errata/$erratum_type Policies/$erratum_name
errata_path =/LSB/Errata/$parent_channel_name/$channel_name Advisory Roll-Up Policy_03_2016
package_path=/LSB/Packages/Unapproved/$channel_name
Is there any solution for this question?
$in$channel(e.g.s/\$channel...) otherwise it will expand to nothing and your command will resolve tos/ Policy/ Policy_03_2016/g