LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to copy specific content of a dynamic file to another flie (https://www.linuxquestions.org/questions/linux-software-2/how-to-copy-specific-content-of-a-dynamic-file-to-another-flie-716119/)

abhi1 04-01-2009 12:40 PM

How to copy specific content of a dynamic file to another flie
 
Hi Guys,


I want to copy a particular content of a dynamic file, which keeps on updating. Is there any way of doing it by using linux commands.

stress_junkie 04-01-2009 01:22 PM

There are several bash commands that will accomplish this. I would use grep. If the file to search is /var/log/messages and the search string is USB then the following command would copy all lines in /var/log/messages containing the letters USB to a file called output.txt.

Code:

grep USB /var/log/messages > output.txt

i92guboj 04-01-2009 01:25 PM

You could try to look into inotifywait to set a watch on that file, and parse its contents with sed, awk or whatever each time it's modified.

A basic watch would be:

Code:

inotifywait --monitor --even modify --format %w foo | \
  while read file
  do
    echo "do whatever with file named \"$file\""
  done

Now each time that the file called "foo" in the current directory changes, the while loop will be run.

chrism01 04-02-2009 06:15 AM

Something like

tail -f firstfile >newfile
and/or look at the 'tee' cmd


All times are GMT -5. The time now is 10:46 PM.