what can I use sed to search for a string and append /sub1 and some file ../ before search string

Urmi

I have to look through jsp file and look for for string loginpage.jsp and replace with ../loginPage.jsp. I have tried following: 1st try:

    sed -i -e 's/<a id="logo" href="loginPage.jsp"><span class="alt">abc</span>        </a>/<a      id="logo" href="../loginPage.jsp"><span class="alt">abc</span></a>/g' 

2nd try:

    SRC="'loginPage.jsp'"
    DEST="'sub2/loginPage.jsp'"
    sed -i "s/$SRC/$DEST/g" <file path>/test1.jsp

3rd try using line number is file

   var="response.sendRedirect("sub2/loginPage.jsp");"
   sed "19 s/.*/$var/" <file path>/test1.jsp

Could you please guide me how to achieve this? Thanks,

Kent

since your input text has slash too, you should either escape all slashes in your input or use another separator, for example, try these:

sed 's#<....>#replacement#g' file

or

sed -i "s#$SRC#$DEST#g" <file path>/test1.jsp

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

sed command not working with search string

분류에서Dev

How can i add a string to the beginning of every line in a file with sed?

분류에서Dev

How can I extract text before a character or string in a batch file?

분류에서Dev

vim: use string from search in replace command

분류에서Dev

Reusing stream of sed for string append

분류에서Dev

how to use sed to replace some pattern with a list of string in bash

분류에서Dev

string search using awk

분류에서Dev

Search a string without . character

분류에서Dev

C# Full-text search string format : string remove all adjacent duplicates and append with 'AND' 'OR'

분류에서Dev

How can I right trim a string with sed - and not kill the string if the pattern is not there?

분류에서Dev

Search a string between two timestamps starting from bottom of log file

분류에서Dev

Find string pattern in file/input, Context dependent search, (not like grep)

분류에서Dev

Search for pattern and append line to another file

분류에서Dev

Assign values to variable from text file. Search for the string in file. Replace the string in file?

분류에서Dev

search file for a string (taken from file) then replace any instance of a different string that falls within the first match

분류에서Dev

Search and replace a word in a string in Scala

분류에서Dev

Search for character in string, within an loop

분류에서Dev

how to search a string for a character and no where it is in the string then change it

분류에서Dev

how to search a string for a character and no where it is in the string then change it

분류에서Dev

Using a search string read another string

분류에서Dev

I want to use memset to remove some characters from string

분류에서Dev

how to copy the dynamic file name and append some string while copying into other directory in unix

분류에서Dev

how can i search for values that have "-" dash in them with elastic search

분류에서Dev

Search for a particular string in Oracle clob column

분류에서Dev

mysql search string and numbers like #654

분류에서Dev

indexOf, search up the string instead of down

분류에서Dev

Search for string containing wild cards in python

분류에서Dev

Search AngularJS resource using query string

분류에서Dev

regex to search for a string that matches almost anything except a |

Related 관련 기사

  1. 1

    sed command not working with search string

  2. 2

    How can i add a string to the beginning of every line in a file with sed?

  3. 3

    How can I extract text before a character or string in a batch file?

  4. 4

    vim: use string from search in replace command

  5. 5

    Reusing stream of sed for string append

  6. 6

    how to use sed to replace some pattern with a list of string in bash

  7. 7

    string search using awk

  8. 8

    Search a string without . character

  9. 9

    C# Full-text search string format : string remove all adjacent duplicates and append with 'AND' 'OR'

  10. 10

    How can I right trim a string with sed - and not kill the string if the pattern is not there?

  11. 11

    Search a string between two timestamps starting from bottom of log file

  12. 12

    Find string pattern in file/input, Context dependent search, (not like grep)

  13. 13

    Search for pattern and append line to another file

  14. 14

    Assign values to variable from text file. Search for the string in file. Replace the string in file?

  15. 15

    search file for a string (taken from file) then replace any instance of a different string that falls within the first match

  16. 16

    Search and replace a word in a string in Scala

  17. 17

    Search for character in string, within an loop

  18. 18

    how to search a string for a character and no where it is in the string then change it

  19. 19

    how to search a string for a character and no where it is in the string then change it

  20. 20

    Using a search string read another string

  21. 21

    I want to use memset to remove some characters from string

  22. 22

    how to copy the dynamic file name and append some string while copying into other directory in unix

  23. 23

    how can i search for values that have "-" dash in them with elastic search

  24. 24

    Search for a particular string in Oracle clob column

  25. 25

    mysql search string and numbers like #654

  26. 26

    indexOf, search up the string instead of down

  27. 27

    Search for string containing wild cards in python

  28. 28

    Search AngularJS resource using query string

  29. 29

    regex to search for a string that matches almost anything except a |

뜨겁다태그

보관