Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Quoted anonymous :
"When doing `./executable > file.txt`,
the file is not continuously written to; ie. the program output goes to some sort of buffer which is transferred to the file in chunks after quite a long time or when the execution of the file stops. Is there any way to make the updation of the file more frequent?"
I am trying to make a script to capture output from hcidump, use a sed substitution to filter out extra data from hcidump, and I tee that to a file on a SSD, and to stdout on the screen. I want to see realtime data on the stdout since this application is detecting new devices all the time, and visual feedback is necessary for good antenna placement in the field. Without the tee command I see the filtered output from sed on stdout in real time. As soon as I add a tee or try and redirect it to a file I start seeing a delay.
The sed 'w' command appends the contents of the pattern space to a file. http://www.gnu.org/software/sed/manu...Other-Commands
I don't have 'hcidump', however this method works using 'free -k -s 1' instead of 'hcidump'
Code:
sudo hcidump -Vt | sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $FILENAME"
If I'm not mistaken this is on a per-program basis. tail will dump ever 1 second, for example, while most other programs will not until the buffer is full.
This is great! This works perfect because it writes unbuffered to the file, and still displays the output on stdout. Thank you guru.
One minor follow-up question... I have to put the literal path of the output file. When I use
Code:
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w ~/Desktop/$FILENAME"
I get a "could't open file" error. If I replace the ~ with /home/user it works well. Is there a way to make ~? its not a big deal but would be nice for portability.
Thank you also for the perl solution. That seems like it would work well too. I may end up converting this sh script to perl if it gets any more complicated, so that was useful info.
Quote:
Originally Posted by Kenhelm
The sed 'w' command appends the contents of the pattern space to a file. http://www.gnu.org/software/sed/manu...Other-Commands
I don't have 'hcidump', however this method works using 'free -k -s 1' instead of 'hcidump'
Code:
sudo hcidump -Vt | sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $FILENAME"
# The Bash shell variable $HOME can be used instead of ~
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $HOME/Desktop/$FILENAME"
# This is a way of getting ~ to work
sed -n 'N;s_<PATTERN>_<REPLACE>_p'"w $(echo ~)/Desktop/$FILENAME"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.