Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-30-2011, 11:08 AM   #1
LQ Newbie
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
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:


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...


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!
Old 06-30-2011, 11:16 AM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Something like this?
while read line
  echo The new line is: $x
done < <(tail -f file)
Old 06-30-2011, 11:35 AM   #3
LQ Newbie
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks, let me try that.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing perl variable into input tag in cgi script shifter Programming 1 08-27-2010 07:13 PM
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 08:59 PM
[SOLVED] Assigning (tail) results to a variable WhisperiN Programming 4 10-17-2009 09:33 AM
Bash: using file as input for grep/tail and then some.. sleipnir Programming 5 06-18-2009 05:51 PM
variable in a tail command jadeddog Programming 4 06-29-2008 10:35 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:38 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration