sed replace exact match

后端 未结 3 625
暗喜
暗喜 2021-02-03 10:34

I want to change some names in a file using sed. This is how the file looks like:

#! /bin/bash

SAMPLE=\"sample_name\"
FULLSAMPLE=\"full_sample_name\"

...
         


        
3条回答
  •  臣服心动
    2021-02-03 11:13

    @user1987607

    You can do this the following way:

    sed s/"sample_name">/sample_01/g

    where having "sample_name" in quotes " " matches the exact string value.

    /g is for global replacement.

    If "sample_name" occurs like this ifsample_name and you want to replace that as well then you should use the following:

    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.

    If you are interested in replacing only first occurence, then this would work fine

    sed s/"sample_name"/sample_01/

    Hope it helps

提交回复
热议问题