ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I'm using weechat-curses as my irc client and I'm trying to create a way to alert me to when something is said. This is what I have as my script:
Code:
#!/bin/bash
tail -0f /home/user/.weechat/logs/irc.server.##channel.weechatlog | while read LINE
do
echo $LINE
echo $LINE | festival --tts
sleep 0.75
done
This would be an example of the log output:
Code:
2011-10-01 18:04:53 @nick aight
The problem is that the "2011-10-01 18:04:53" gets spoken and really draws away from the purpose of using festival. I tried to strip it out with the sed code:
Code:
sed "s/^[0-9]{4}-[0-9]{2}-[0-9]{2}[ ]*[0-9]{2}:[0-9]{2}:[0-9]{2}//"
The problem is that this doesn't give me any output. Anyone have any ideas?
this can be done easily with sed. Even easier with awk:
Code:
awk '{$1="";$2=""}1'
If you are limited to sed:
Code:
sed 's/[^[:blank:]]* *[^[:blank:]]* *//'
Hope this helps.
[EDIT]
BTW, the reason why your solution is not working is because you have to either use escapes like '\{' and '\}' or you need to invoke 'sed' with the '-r' option to enable extended RegEx:
Code:
sed -r 's/<your RegEx>//'
Last edited by crts; 10-01-2011 at 07:58 PM.
Reason: corrected typos
Well, I found the *error*. The awk waits to process the complete file before it flushes its output through the pipe. Since there is no EOF the input is stuck in the middle of the pipe. Try this instead:
ctrs: I'll have to give that code a try. I ended up resorting to using "script -c". It works but I went back to the sed statement because of my laziness.
I'm probably going to spend the next little while cleaning it up to get rid of logins, logouts, and shorten those long paragraphs down to like 14 or so words.
Code:
script -c "tail -0f /home/user/.weechat/logs/irc.server.#channel.weechatlog | sed 's/[^[:blank:]]* *[^[:blank:]]* *//'" /dev/null | while read LINE
do
echo $LINE
echo $LINE | festival --tts
sleep 0.75
done
ctrs: I'll have to give that code a try. I ended up resorting to using "script -c". It works but I went back to the sed statement because of my laziness.
I'm probably going to spend the next little while cleaning it up to get rid of logins, logouts, and shorten those long paragraphs down to like 14 or so words.
Code:
script -c "tail -0f /home/user/.weechat/logs/irc.server.#channel.weechatlog | sed 's/[^[:blank:]]* *[^[:blank:]]* *//'" /dev/null | while read LINE
do
echo $LINE
echo $LINE | festival --tts
sleep 0.75
done
Thanks for the help
Ok, don't mean to sound harsh but this is bad. I am not familiar with script but from what I have read so far in the man-page this is not its main purpose. Have another look at post #5. The solution is to not pipe 'tail -0f' into awk. Instead let 'tail -0f' feed the loop only and then modify the variable with awk.
If you want to use sed and are willing to replace festival with espeak then you could do something like this:
Code:
tail -0f file | sed -u 's/[^[:blank:]]* *[^[:blank:]]* *//'|espeak
That's it. It doesn't need a loop. The -u option tells sed to output immediately; without buffering. 'espeak' also does process the input line by line rather than waiting for the whole input to finish like festival does. However, espeak's speech quality is not as good as festival's.
Yeah, I did not see that right at the beginning and then I got caught up with that pipe issue. That is, which programs can deal with neverending input and which cannot. So, apparently awk and festival cannot deal with it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.