Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This 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.


  Search this Thread
Old 04-01-2009, 12:40 PM   #1
LQ Newbie
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
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.
Old 04-01-2009, 01:22 PM   #2
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
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.

grep USB /var/log/messages > output.txt
Old 04-01-2009, 01:25 PM   #3
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,060

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

inotifywait --monitor --even modify --format %w foo | \
  while read file
    echo "do whatever with file named \"$file\""
Now each time that the file called "foo" in the current directory changes, the while loop will be run.
Old 04-02-2009, 06:15 AM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,204

Rep: Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311Reputation: 2311
Something like

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


content, copy, file, particular

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
SCP copy file with dynamic date( or something like that) Shinigami101 Linux - Software 3 11-19-2008 07:56 AM
Huge Data Set Analysis, Shell Script to copy specific HEX Pairs into a separate file telecom_is_me Programming 11 06-29-2008 10:48 PM
How to do recursive file copy of directory for specific files? Arodef Linux - Newbie 4 06-29-2004 05:35 PM
PHP - dynamic content jacksmash Programming 11 11-25-2003 02:43 PM
How to copy a selected content from a .PDF file satimis Linux - General 3 07-03-2003 04:18 AM

All times are GMT -5. The time now is 10:58 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