Find the answer to your Linux question:
Results 1 to 3 of 3
Hi All, I'm a linux user, but definitely no expert and would like to ask if someone can help me in writing a linux or awk script which can concatenate ...
  1. #1
    Just Joined!
    Join Date
    Feb 2005
    Posts
    5

    Linux or awk script to add default string to lines

    Hi All,

    I'm a linux user, but definitely no expert and would like to ask if someone can help me in writing a linux or awk script which can concatenate a default string to each line in a file.

    For example, I would like add "This is the end" to all lines in a certain file, so that after running the script the file would look like:
    This is line 1 This is the end
    This is line 2 This is the end
    Some text on line 3 This is the end
    ...

    I'm sure that fore some more experienced uses this must be a piece of cake It would be great if those could help me out.

    Thank you

  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    658
    Hi there,

    Code:
    chris@angua:~/dev/scratch$ cat test2.txt 
    This is line 1
    This is line 2
    Some text on line 3
    chris@angua:~/dev/scratch$ sed 's/$/ This is the end/' test2.txt > test3.txt
    chris@angua:~/dev/scratch$ cat test3.txt 
    This is line 1 This is the end
    This is line 2 This is the end
    Some text on line 3 This is the end
    The $ is the regular expression for the end of the line so it matches that and replaces it with your end string.

    Let us know how you get on.
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    Just Joined!
    Join Date
    Feb 2005
    Posts
    5
    Worked like a charm.. many thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...