Find the answer to your Linux question:
Results 1 to 3 of 3
Let's say I have only one line in alien.x like this: Code: humans And I wanted to append to the end of that line this: Code: =food How would I ...
  1. #1
    Linux User Agent-X's Avatar
    Join Date
    May 2005
    Location
    Dimension X
    Posts
    261

    Append text to the ending part of a line?

    Let's say I have only one line in alien.x like this:

    Code:
    humans
    And I wanted to append to the end of that line this:

    Code:
    =food
    How would I do that so it looks like this:
    Code:
    humans=food
    ??

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Some possibilities:

    Code:
    sed 's/humans/humans=food/'
    Code:
    sed 's/\(.*\)/\1=food/'
    Code:
    awk '{printf("%s=food", $0}'
    Regards

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    A common way is also:
    Code:
    sed 's/$/=food/'
    This replaces the end-of-line marker (denoted by '$') with the test '=food'. '$' isn't actually in the file (it's what regular expressions call an "anchor", so this doesn't actually replace anything.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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