Echo command: New line BEFORE text

Discussion in 'Mac Basics and Help' started by Jynxxander, Mar 14, 2009.

  1. Jynxxander macrumors member

    Joined:
    Sep 7, 2008
    #1
    Sure echo -n (text) let's you output something in a new line, but is there anyway to make that line the first line in a txt document?
     
  2. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #2
    You mean to append a line to the beginning of an existing document? ("Prepend"?)

    Code:
    1
    2
    3
    4
    becomes

    Code:
    inserted text
    1
    2
    3
    4
     
  3. Jynxxander thread starter macrumors member

    Joined:
    Sep 7, 2008
    #3
    Yes yes! Exactly, I can't seem to figure it out...
     
  4. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #4
    Hmm, that's odd. I can't think of an easy way to do it with a single command. What exactly are you trying to set up here?

    By the way, echo -n outputs text that does not have a line break after.
     
  5. Jynxxander thread starter macrumors member

    Joined:
    Sep 7, 2008
    #5
    It's actually for an applescript for Geektool.
    Anyway, I found something

    Code:
    cat FILE | pbcopy && echo "TEXT" > FILE  && pbpaste >> FILE 
    :D
     
  6. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #6
    Hmm, I'll have to remember that one. I was going to recommend something similar, but I would've had to use a temporary file, which would be pretty messy.
     
  7. scienide09 macrumors 65816

    scienide09

    Joined:
    May 5, 2007
    Location:
    Canada
    #7
    I don't know of a method, but just did a bit of searching, and found a workaround that may suit your needs.

    Open the file, and grab the contents currently there. Then file append to add whatever you need to add. Then re-insert the old contents below.

    You've probably seen this, but in case you haven't...
     
  8. Jynxxander thread starter macrumors member

    Joined:
    Sep 7, 2008
    #8
    I've already found something, but thanks for your suggestion.
     

Share This Page