Reputation: 1285
I have a condition where I want to find and replace all '/ ' (forward / with a space after that) in a file for some lines having a specific entries. Example below:
g aaa / cccc dd
k eee / hhhh dd
m aaa / kkkk ll
I want to replace '/ ' with '/' for the rows with 'aaa' entry.
Upvotes: 1
Views: 194
Reputation: 490
Like this?
perl -pe '/aaa/ and s[/ ][/]'
Of course it can be refined in many ways, e.g., add g
to the s[][]
to replace all matches, add the -i
switch to edit files “in place”, etc.
Upvotes: 2