LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-11-2008, 07:39 AM   #1
pudhiyavan
Member
 
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209

Rep: Reputation: 30
cat|grep|awk


i have files like jul07, jul08 which contains a data as follow

Wed Jul 9 16:45:01 IST 2008
Mem Used 744
hddMounted Used Avail
/apps 2.2G 31G


now i need to have the time (16:45) and Mem used (744) tobe extracted and display in timely order

can anyone help me?

cat Jul090000 |grep 'Mem Used' |awk '{print $3}' gives me 744 how to add 16;45 along with this?

Last edited by pudhiyavan; 07-11-2008 at 07:47 AM. Reason: cat command
 
Old 07-11-2008, 08:00 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Use the same technique to extract "16:45" and put it in a variable. Then use that variable in combination with the other command.

really good AWK tutorial here:
http://www.grymoire.com/Unix/Awk.html
 
Old 07-11-2008, 08:03 AM   #3
pudhiyavan
Member
 
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209

Original Poster
Rep: Reputation: 30
but i have multiple files like this,
 
Old 07-11-2008, 08:10 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
To do the same thing on multiple files, you would simply put your script in a structure such as this:

Suppose your script is "wordsmasher", and you have all your files in one directory:

for file in ls; do
wordsmasher $file
<<other commands>>
done
 
Old 07-11-2008, 08:14 AM   #5
pudhiyavan
Member
 
Registered: Oct 2003
Location: Linux world
Distribution: redhat,mandy,centos,debian,ubuntu
Posts: 209

Original Poster
Rep: Reputation: 30
Thanks for your help
 
Old 07-14-2008, 01:36 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
You could grab the time like this:

head -1 <yourfilename>|awk '{print $4}'
 
Old 07-14-2008, 01:56 AM   #7
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Code:
$ cat data1 data2

Wed Jul 9 16:45:01 IST 2008
Mem Used 744
hddMounted Used Avail
/apps 2.2G 31G


Wed Jul 8 12:45:01 IST 2008
Mem Used 894
hddMounted Used Avail
/apps 2.2G 31G

$ perl -e '$/ = undef; while ($_ = <>) { print "$1 $2\n" if /\w{3} \w{3} +\d+ (\d{2}:\d{2}):\d{2}.*\nMem Used (\d+)/}' data*
16:45 744
12:45 894
 
  


Reply


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
cat and grep dipuasks Linux - General 11 04-21-2008 03:39 AM
cat to grep to textfile? jabfinger Linux - General 3 09-05-2006 03:25 PM
cat [file] | grep --- trouble bob_man_uk Linux - General 12 03-10-2006 06:05 AM
Question About Cat And Grep George2 Linux - Software 10 03-09-2006 03:33 AM
output to a file - cat? grep? Godsmacker777 Linux - Newbie 6 12-08-2004 10:06 AM


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