Sponsored Content
Top Forums Shell Programming and Scripting Display file date after grepping a string in the file Post 302644933 by quemalr on Tuesday 22nd of May 2012 05:57:52 PM
Old 05-22-2012
Question Display file date after grepping a string in the file

Hi All,

I need to recursively grep several folders for a MAC address and display the results with the date of the file name at the start. Even better would be if the final results were displayed chronologically so the newest file is always at the end. Oldest at the top, regardless of what directory it was in.

The search starts at

/opt/com21/nmaps/snmp/modemdata

EG:

Code:
root@NMAPS-A1 modemdata]# grep -r 0:15:a3:e2:f8:c7 * | sort -r

Output is (note there could be hundreds of results)
Code:
mish1/modemlevelsMish1.csv08092508:320:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-30,262,340,2771687393,10,0,2771765396,10,0
mish1/modemlevelsMish1.csv08092408:325:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-16,272,340,1650163261,3,0,1650241264,3,0
mish1/modemlevelsMish1.csv08092308:323:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-16,269,340,526142531,3,0,526142531,3,0
mish1/modemlevelsMish1.csv08092008:326:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-31,263,350,3912425699,6,0,3912425699,6,0
mish1/modemlevelsMish1.csv08091908:319:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-33,255,350,2788951199,6,0,2789029202,6,0
mish1/modemlevelsMish1.csv08091808:324:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-26,265,360,1664462990,6,0,1664540993,6,0
mish1/modemlevelsMish1.csv08091708:318:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-18,268,360,543875389,2,0,543875389,2,0
mish1/modemlevelsMish1.csv08091614:322:192.168.22.253,0:15:a3:e2:f8:c7,250000000,24000000,-16,272,340,1542683488,10227,1034,1542683488,10227,1034
Knock7/modemlevelsKnock7.csv12020522:227:192.168.95.75,0:15:a3:e2:f8:c7,274000000,18600000,-23,266,330,,41602,0,704484102,41602,0
Knock7/modemlevelsKnock7.csv12020422:227:192.168.95.75,0:15:a3:e2:f8:c7,274000000,18600000,-9,273,320,2269039706,24149,0,2269229200,24149,0
Knock7/modemlevelsKnock7.csv12020321:230:192.168.95.75,0:15:a3:e2:f8:c7,274000000,,,275,320,3756465866,13229,0,3756465866,13229,0
Knock1/modemlevelsKnock1.csv12022122:80:192.168.12.127,0:15:a3:e2:f8:c7,256000000,31400000,-66,241,340,469848408,19876103,10,469925662,19876851,10
Knock1/modemlevelsKnock1.csv12022022:68:192.168.12.127,0:15:a3:e2:f8:c7,256000000,31400000,-63,229,340,3648043108,13423757,10,3648043108,13423757,10
Knock1/modemlevelsKnock1.csv12021922:62:192.168.12.127,0:15:a3:e2:f8:c7,256000000,31400000,-48,256,330,2530162130,7754073,10,2530162130,7754073,10
Knock1/modemlevelsKnock1.csv12021822:70:192.168.12.127,0:15:a3:e2:f8:c7,256000000,31400000,-45,259,320,1411569669,3419626,0,1411569669,3419626,0
Knock1/modemlevelsKnock1.csv12021722:80:192.168.12.127,0:15:a3:e2:f8:c7,256000000,31400000,-59,232,330,290816964,1040554,0,290816964,1040554,0
Knock1/modemlevelsKnock1.csv12021622:8:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-64,246,340,3148191623,22637172,678615,3148191623,22637172,678615
Knock1/modemlevelsKnock1.csv12021522:9:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-57,248,330,2039658009,8482050,360918,2039734114,8483880,360987
Knock1/modemlevelsKnock1.csv12021422:9:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-55,256,330,925261982,11,0,925339984,11,0
Knock1/modemlevelsKnock1.csv12021322:8:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-51,258,330,4097068359,10,0,4097068359,10,0
Knock1/modemlevelsKnock1.csv12021222:8:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-60,252,340,2974019233,10,0,2974019233,10,0
Knock1/modemlevelsKnock1.csv12021122:7:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-53,252,330,1850779668,8,0,1850857670,8,0
Knock1/modemlevelsKnock1.csv12021022:6:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-62,250,340,727539103,8,0,727617105,8,0
Knock1/modemlevelsKnock1.csv12020922:5:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-54,260,340,3899376153,8,0,3899454155,8,0
Knock1/modemlevelsKnock1.csv12020822:7:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-60,250,340,2776416010,7,0,2776494013,7,0
Knock1/modemlevelsKnock1.csv12020722:7:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-59,253,330,1653310971,5,0,1653388974,5,0
Knock1/modemlevelsKnock1.csv12020622:8:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-43,264,320,530476324,4,0,530554327,4,0

Id rather have

Code:
22-May-2012-Knock1/modemlevelsKnock1.csv12020622:8:192.168.12.17,0:15:a3:e2:f8:c7,256000000,31400000,-43,264,320,530476324,4,0,530554327,4,0

Etc..

Moderator's Comments:
Mod Comment Code tags for code, please.

Or truncate the file name part of the result to just the date part as all are format .csvYYMMDDHH and then display all results regardless of the directory chronologically.

Thanks in advance for any tips. Hope I explained it well enough.

These files are created daily and never written to again so I can go by time stamp of the file.

Q.

Last edited by Scrutinizer; 06-11-2012 at 10:59 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

display the file with in the date range

Hi All, I want a shell script which can display the file with in the date range. For Example I have 15 files with the following format abc_01-01-2009.txt to abc_15-01-2009.txt. Now I want to have the files between 4th of jan to 12th files. How can I acheive this. Advance... (1 Reply)
Discussion started by: fareed_do
1 Replies

2. Shell Programming and Scripting

Grepping string from out file

Guys .. Need to pull this highlighted strings irrespective of line numbers & should be echoed . But these strings are from Outfile from different dir. In which way this can be grepped ?? Need an idea http-timeout 120 seconds persistent-timeout 180 seconds host-rewriting on ... (7 Replies)
Discussion started by: raghunsi
7 Replies

3. AIX

Help with looping a file and grepping a string

I have 2 files: fileA and fileB. content of fileA --------------- admin.teacher is in new york; admin.mason is in new york; admin.driver is in new york city; user.trucker is in hartford; admin.developer is in new york state; content of fileB ---------------- admin.teacher is in... (8 Replies)
Discussion started by: lowprofile
8 Replies

4. Shell Programming and Scripting

How to search for file and display by date

I like "ls -ltr". I would like to search for a file in a large directory recursively and and display all the candidates in reverse order. /usr/bin/find . -name \*.txt This works. How do I display the date and sort the file names by the date in reverse order for the entire directory... (1 Reply)
Discussion started by: siegfried
1 Replies

5. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

6. Shell Programming and Scripting

Display lines of two date range from syslog file

Hi Guys, I want to display lines from Solaris syslog file but with 2 dates range. I have some similar solution (https://www.unix.com/shell-programming-scripting/39293-grep-log-file-between-2-dates-4.html) which works fine but as you know syslog has different date format (Jan 22) so this is not... (1 Reply)
Discussion started by: prashant2507198
1 Replies

7. Shell Programming and Scripting

Extract count of string in all files and display on date wise

Hi All, hope you all are doing well! I kindly ask you for shell scripting help, here is the description: I have huge number of files shown below on date wise, which contains different strings(numbers you can say) including 505001 and 602001. ... (14 Replies)
Discussion started by: VasuKukkapalli
14 Replies

8. AIX

How do I display a file's last modified date?

I'm using a script that I need to get a file's "last modified date" in a format like 01:51:14 PM. We are running on AIX 6.1.0.0. I can't seem to find the right command parameters. Help! (4 Replies)
Discussion started by: mattadams1983
4 Replies

9. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

10. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies
All times are GMT -4. The time now is 08:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy