LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-01-2009, 12:40 PM   #1
abhi1
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
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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
 
Old 04-01-2009, 01:25 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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.
 
Old 04-02-2009, 06:15 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Something like

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


Reply

Tags
content, copy, file, particular



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:21 AM.

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