Sponsored Content
Top Forums Shell Programming and Scripting Display file date after grepping a string in the file Post 302645107 by quemalr on Wednesday 23rd of May 2012 04:13:24 AM
Old 05-23-2012
Hello Neutronscott,

Its a bash shell and I'm writing a script using Fedora.
I want to append the 22-May-2012 bit to the start of the line for each result.

More importantly would be having the data listed in chronological order or just list the contents of the most recent directories. Its modem data on our network I'm looking at. The contents of the directory where the files are is as follows:


Code:
[
[root@NMAPS-A1 modemdata]# pwd
/opt/com21/nmaps/snmp/modemdata
root@NMAPS-A1 modemdata]# ls -ltr
total 848
drwxr-xr-x 2 root root  4096 Jan 17 07:14 knock10
drwxr-xr-x 2 root root  4096 Jan 27 11:20 fmtn3
drwxr-xr-x 2 root root  4096 Jan 27 18:03 Wmtn1
drwxr-xr-x 2 root root 12288 Jan 28 05:56 balling1
drwxr-xr-x 2 root root 36864 Jan 28 06:03 fmtn1
drwxr-xr-x 2 root root 32768 Jan 28 07:00 johns1
drwxr-xr-x 2 root root 36864 Jan 28 07:13 knock1
drwxr-xr-x 2 root root 45056 Jan 28 07:43 knock2
drwxr-xr-x 2 root root 24576 Jan 28 08:11 knock3
drwxr-xr-x 2 root root 36864 Jan 28 09:08 mish1
drwxr-xr-x 2 root root 36864 Jan 28 10:03 mish2
drwxr-xr-x 2 root root 24576 Jan 28 10:36 mish3
drwxr-xr-x 2 root root 40960 Jan 28 11:04 slieveb1
drwxr-xr-x 2 root root  4096 Jan 28 17:13 Knock8
drwxr-xr-x 2 root root  4096 Jan 29 22:01 Wmtn4
drwxr-xr-x 2 root root  4096 Feb  2 15:58 mtgabhcx
drwxr-xr-x 2 root root  4096 Feb  8 09:28 Knock10_4
-rw-r--r-- 1 root root 98443 Feb  8 10:47 Knock10all
drwxr-xr-x 2 root root  4096 Feb 15 22:01 Mish5
drwxr-xr-x 2 root root  4096 Feb 15 22:01 Mish3
drwxr-xr-x 2 root root  4096 Feb 17 14:27 comp
drwxr-xr-x 2 root root  4096 Feb 20 18:24 Knock9
drwxr-xr-x 2 root root  4096 Feb 23 19:18 reports
drwxr-xr-x 2 root root 24576 Feb 29 08:11 fmtn2
-rw------- 1 root root 21744 Feb 29 10:54 nohup.out
drwxr-xr-x 2 root root  4096 Mar  4 20:47 knock5
drwxr-xr-x 2 root root  4096 Mar  8 11:07 Knock7
drwxr-xr-x 2 root root  4096 Mar  8 11:10 Knock3
-rw-r--r-- 1 root root  1032 Mar 31 13:44 1.1
drwxr-xr-x 2 root root  4096 May 16 16:45 Knock11
drwxr-xr-x 2 root root 12288 May 22 22:01 Slieveb2
drwxr-xr-x 2 root root 12288 May 22 22:01 Slieveb1
drwxr-xr-x 2 root root  4096 May 22 22:01 Mish7
drwxr-xr-x 2 root root 12288 May 22 22:01 Mish4
drwxr-xr-x 2 root root 12288 May 22 22:01 Mish2
drwxr-xr-x 2 root root 12288 May 22 22:01 Mish1
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock2
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock10_3
drwxr-xr-x 2 root root 12288 May 22 22:01 Johnsw1
drwxr-xr-x 2 root root 12288 May 22 22:01 Forth3
drwxr-xr-x 2 root root 12288 May 22 22:01 Forth2
drwxr-xr-x 2 root root 12288 May 22 22:01 Balling1
drwxr-xr-x 2 root root  4096 May 22 22:01 Forth4
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock10_2
drwxr-xr-x 2 root root 12288 May 22 22:01 Forth1
drwxr-xr-x 2 root root  4096 May 22 22:01 Slieveb3
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock5
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock1
drwxr-xr-x 2 root root 12288 May 22 22:01 Wmtn3
drwxr-xr-x 2 root root 12288 May 22 22:01 Wmtn2
drwxr-xr-x 2 root root 12288 May 22 22:01 Coolg1
drwxr-xr-x 2 root root 12288 May 22 22:01 MtGab1
drwxr-xr-x 2 root root 12288 May 22 22:01 Clara1
drwxr-xr-x 2 root root 12288 May 22 22:01 Knock10_1
drwxr-xr-x 2 root root  4096 May 22 22:01 Forth5
drwxr-xr-x 2 root root 12288 May 22 22:01 Mish6
-rw-r--r-- 1 root root  1051 May 22 23:00 null
drwxr-xr-x 2 root root  4096 May 23 05:30 wmtn1
drwxr-xr-x 2 root root  4096 May 23 05:31 crushum1
drwxr-xr-x 2 root root  4096 May 23 05:34 cheekp1
drwxr-xr-x 2 root root  4096 May 23 05:34 clara1
drwxr-xr-x 2 root root  4096 May 23 05:34 duagh
drwxr-xr-x 2 root root  4096 May 23 05:34 bweeng1

So the only directories to be queried for the string is the directories last written to 1 day ago or with the current date.
 

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 11:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy