Monday, 15 July 2013

bash - How can I replace a word at a specific line in a file in unix -


I have searched for other questions here, but in reality there is no one working for me. I am trying to select a specific line and change that string with another string. So I have a file called my_course, which I'm trying to modify a row in "my_search" which starts with "123" on that line I want to change the string with "0", "1". Help

A possibility sed :

  Sed '/ ^ 123 / s / 0/1 /' my_course   
  • In the first /../ Specify the pattern that you are looking for ^ 123 for the line beginning with 123

  • You want:
    • Redirect the output using ...;

    • If you are using destructive version of the location, then you have given the original version when anything went wrong. Besides placing a copy with the extension, you will want to use -iEXTENSION .

      Edit: To match the desired lineup with a prefix stored in one variable, you will need to add the sed script with double quotes using a single code " ' will prevent variable extension:

        sed "/ ^ $ input / s / 0/1 /" my_course    

No comments:

Post a Comment