LinuxQuestions.org
Help answer threads with 0 replies.
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, 01: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, 02: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: 331Reputation: 331Reputation: 331Reputation: 331
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, 02:25 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,043

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
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, 07:15 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Something like

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


Reply

Tags
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 08: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 11:48 PM
How to do recursive file copy of directory for specific files? Arodef Linux - Newbie 4 06-29-2004 06:35 PM
PHP - dynamic content jacksmash Programming 11 11-25-2003 03:43 PM
How to copy a selected content from a .PDF file satimis Linux - General 3 07-03-2003 05:18 AM


All times are GMT -5. The time now is 06:50 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration