简体   繁体   中英

How to replace a string in multiple files in linux command

I need to replace a string in a lot of files in a folder, with only ssh access to the server. How can I do this?

for example i want replace all files Which contains code

<script src='http://cdn.adplxmd.com/adplexmedia/tags/xbanner/xbanner.js?ap=1300' type='text/javascript'></script>

I want replace it with my name: sultan

I do something like this:

sed -i 's/<script src='http://cdn.adplxmd.com/adplexmedia/tags/xbanner/xbanner.js?ap=1300' type='text/javascript'></script>/sultan/g' *

but the problem i see error message in linux commands:

sed: -e expression #1, char 20: unknown option to `s'

How do I fix this problems?

There are two errors:

  1. the slash is used as a delimiter in your call to sed, so this ambiguity needs to be resolve
  2. you're using single quotes in the search term but also to enclose the sed parameter.

You can try something like this instead:

sed -i "s|<script src='http://cdn.adplxmd.com/adplexmedia/tags/xbanner/xbanner.js?ap=1300' type='text/javascript'></script>|sultan|g" *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM