Results 1 to 6 of 6

Thread: Shell script with sed

  1. #1
    Join Date
    Jul 2009
    Posts
    140

    Shell script with sed

    Hello
    I have an amendment to a file and I do not know how to manage the spaces or tabs in a row
    In short: I try to modify a line that would word1 word2 and word3 separated by spaces or tabs to add mot4 him to finish. Any idea how to accomplish it? Thank you in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Shell script with sed

    Hi
    Any idea how to accomplish it?
    I think you can use the following line of code to complete you program.
    Code:
    sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt

  3. #3
    Join Date
    Jul 2009
    Posts
    140

    Re: Shell script with sed

    Hi
    sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt
    Thanks for the part of the code. But till now I have this with me
    Code:
    sed '/ password / s /.*/& Test' system
    I have not really tried you part of code, but I will soon.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Shell script with sed

    Hello
    sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt
    1 - / ^ \ (arg1. * arg2 \ ).*$/
    - From the beginning of line ^
    - I put in a buffer inside the expression contained in parentheses: \ (\). Attention is to precede the brackets \.
    - I'll just end of line .* $ (any character repeated zero )

    2 - & 1 ADD
    - I copy buffer1: & 1
    - And add ADD: ADD

    when I reread it could even change the order in
    Code:
    sed-i-e 's / ^ \ (arg1. * arg2 .* \) $ / & 1 ADD / g' file.txt
    Any more query do post back.

  5. #5
    Join Date
    Jul 2009
    Posts
    140

    Re: Shell script with sed

    Hi
    I want to add the line after the first line that starts with password. I found nothing better than:
    sed-i '/ ^ .* password requisite / a \ test' system
    I had to add a second word to recognize the line.
    We can not well avoid it? for it does not add as many as there is line beginning with password.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Shell script with sed

    Hello
    s / regexp / replacement /
    Attempt to match regexp in the workspace. If successful, replace with the replacement part that is. The replacement may contain the special character & to refer to that portion of the workspace that match, and special characters \ 1 through \ 9 to refer to sub expressions, matched with regexp matching.

Similar Threads

  1. shell script SSH not working
    By Lilya in forum Software Development
    Replies: 9
    Last Post: 16-10-2010, 01:53 AM
  2. Shell script to add the extension to doc and pdf files
    By Tailor in forum Software Development
    Replies: 4
    Last Post: 24-02-2010, 10:51 PM
  3. Shell Script Formatting
    By abhi701 in forum Software Development
    Replies: 1
    Last Post: 04-07-2009, 04:30 PM
  4. Problem of shell script on Linux
    By $tatic in forum Software Development
    Replies: 4
    Last Post: 16-04-2009, 09:08 PM
  5. Unix Shell Script
    By BlackSunReyes in forum Software Development
    Replies: 3
    Last Post: 12-08-2008, 01:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,232,271.49747 seconds with 17 queries