I'm currently using 's/string/new_string/g'
to go through some CSV files, however I'm running into difficulty in the following scenario:
I want to replace instances of '192.168.0.11'
, however it's also catching instances of '192.168.0.111'
.
How can I ensure sed only grabs '192.168.0.11'
and not '192.168.0.111'
? I'll obviously have to repeat this for many variables, so something easily scalable would be appreciated.
Thanks!
sed s/"sample_name ">/"sample_01 "/g So that it replaces only the desired word. For example the above syntax will replace word "the" from a text file and not from words like thereby.
The easiest of the two commands is to use grep's -w option. This will find only lines that contain your target word as a complete word. Run the command "grep -w hub" against your target file and you will only see lines that contain the word "hub" as a complete word.
I'm not sure what the regex you are using is, but if you want an exact match of '192.168.0.11' you can use:
s/\<192\.168\.0\.11\>//g
The \<\>
force an exact match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With