LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tail -f as variable input into a script (https://www.linuxquestions.org/questions/linux-newbie-8/tail-f-as-variable-input-into-a-script-889203/)

willyjc1 06-30-2011 10:08 AM

tail -f as variable input into a script
 
I have a file which is continuously receiving new data throughout the day. Currently I use the tail -f command to view the last line to be written to the file as it happens in realtime. However, the data that I am reading in the format of a long, non-delimited string that looks like this:

8=MIX.4.99=19535=M49=LGBD256=MSFTAB115=YAVI34=31950=XYXD57=ABCD

I wrote a script to parse the string and return only the info that i want in a readable form and it works fine. But I am simply using a sample string as the value of variable $x in the script to test it. In other words...

x=8=MIX.4.99=19535=M49=LGBD256=MSFTAB115=YAVI34=31950=XYXD57=ABCD

What I NEED is to have the last line of the file read into the script as the file is updated and set equal to the variable $x. And then of course overwritten each time a new line is written to the file so that the script will return to me the PARSED VERSION of the string to appear on my screen in realtime. Can this be done??

Help will be greatly appreciated!
Thanks

colucix 06-30-2011 10:16 AM

Something like this?
Code:

#!/bin/bash
while read line
do
  x="$line"
  echo The new line is: $x
done < <(tail -f file)


willyjc1 06-30-2011 10:35 AM

Thanks, let me try that.


All times are GMT -5. The time now is 03:31 PM.