unix - Find - replace - Update string using shell script -
i have file containing line like
https://abcdefgh.com/123/pqrst/456/xyz.html
so want search line in file , replace end part i.e. xyz.html
mno.html
will take mno.html
input in shell script.
how ?
$ awk 'begin{fs=ofs="/"} index($0,"https://abcdefgh.com/123/pqrst/456/xyz.html"){$nf="mno.html"} 1' file https://abcdefgh.com/123/pqrst/456/mno.html
or if both values stored in shell variables:
$ old="https://abcdefgh.com/123/pqrst/456/xyz.html" $ new="mno.html" $ awk -v old="$old" -v new="$new" 'begin{fs=ofs="/"} index($0,old){$nf=new} 1' file https://abcdefgh.com/123/pqrst/456/mno.html
Comments
Post a Comment