Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Appending Sed Output to a File

Options
  • 13-03-2012 3:04pm
    #1
    Registered Users Posts: 5,238 ✭✭✭


    (edited so that the first command makes sense)

    I want to parse the input from a tty device and append the output to a file. These are my failed attempts:

    sed "s/Temperature/`date +%c`, Temperature/" /dev/ttyFT232 >> /home/temperature.log

    and

    cat < /dev/ttyFT232 | sed "s/Temperature/`date +%c`, Temperature/" >> /home/temperature.log

    I've tried a lot of variations on these themes but those are the gist. I would use the /w flag but I don't want the output file overwritten each time.

    I've seen similar examples on other websites which are purported to have worked so I just can't understand it.
    Tagged:


Comments

  • Registered Users Posts: 1,931 ✭✭✭PrzemoF


    The first one should work - it works for me on android phone, but I used a file as the source.

    Have you tried to use a file instead of /dev/ttyXXX?

    Is the destination file accesible for writing?

    Can you explain "failed"? (error / no result at all / resulet different than expected)


  • Registered Users Posts: 5,238 ✭✭✭humbert


    That's interesting, it does work with a file.

    The reason I didn't test it with a file is that when I removed the
    >> output_file
    the parsed tty input was being printed to the stdout/terminal correctly, so I assumed no problem with reading from the device. The users group has access to the device and I've tested this successfully using cat and grep.

    Thanks for the suggestion. Still very odd.

    E.g. of output:
    cat:
    Temperature: 20
    Temperature: 21
    Temperature: 19

    sed "s/Temperature/`date +%c`, Temperature/" /dev/ttyFT232:
    14 Mar 2012 18:04:34 Temperature 20
    14 Mar 2012 18:04:44 Temperature 21
    14 Mar 2012 18:05:24 Temperature 21

    Then when I change to
    sed "s/Temperature/`date +%c`, Temperature/" /dev/ttyFT232 >> /home/temperature.log
    There is no text coming to the stdout but nothing going to the file.

    I think I need to test it with more conventional inputs making sure each step works since PrzemoF has shown it's not a problem with the sed command.


  • Registered Users Posts: 1,931 ✭✭✭PrzemoF




Advertisement