List and grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List and grep
# 1  
Old 09-06-2011
Question List and grep

Hi,

My requirement is to copy all yesterdays files which have "access" keyword in their filenames to a separate folder say "/tmp/moht".

Can you please let me know how?
# 2  
Old 09-06-2011
What did you try so far?
# 3  
Old 09-06-2011
Question

Code:
ls -ltr
total 55472
-rw-r--r--   1 admin grp   1684877 Sep  2 20:47 51.error_log_443.201109020000.gz
-rw-r--r--   1 admin grp   26619984 Sep  2 20:48 51.access_log_443.201109020000.gz
-rw-r--r--   1 admin grp     58415 Sep  5 08:07 51.access_log_443.201109050000
-rw-r--r--   1 admin grp     17181 Sep  6 06:51 51.access_log_443.201109060000

Desired output:
Code:
-rw-r--r--   1 admin grp   26619984 Sep  2 20:48 51.access_log_443.201109020000.gz
-rw-r--r--   1 admin grp     58415 Sep  5 08:07 51.access_log_443.201109050000

My output:

Code:
find /apps/logs/ -mtime +1 -exec ls -ltr {} \;
-rw-r--r--   1 admin grp   1684877 Sep  2 20:47 /apps/logs/colweb-perf-0551.error_log_443.201109020000.gz
-rw-r--r--   1 admin grp   26619984 Sep  2 20:48 /apps/logs/51.access_log_443.201109020000.gz

Code:
date
Tue Sep  6 06:54:50 EDT 2011

Post correct filtering I am not even sure how to append the copy command so the output files gets copied to a different folder. I guess xargs may help.

I did not post this prior for i thought i may be misleading those who have better idea.

Regards,
# 4  
Old 09-06-2011
+1 means more than 24 hours ago.
Which operating system are you using?
# 5  
Old 09-06-2011
Question

Yes, thats what i am not sure, how to specify find so that it filters logs of the previous day rather than 24 hrs.

SunOS mymachine 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220
# 6  
Old 09-06-2011
try this ..
Code:
#!/bin/bash
yest_dat_mon=`TZ=CST+24 date +%b`
yest_dat_day=`TZ=CST+24 date +%d | sed 's,^0,,g'`
if [ "$yest_dat_day" -lt 10 ]
then
        ls -ltr|grep " $yest_dat_mon  $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh
else
        ls -ltr|grep " $yest_dat_mon $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh
fi

This User Gave Thanks to jayan_jay For This Post:
# 7  
Old 09-06-2011
Question

Quote:
Originally Posted by jayan_jay
try this ..
Code:
#!/bin/bash
yest_dat_mon=`TZ=CST+24 date +%b`
yest_dat_day=`TZ=CST+24 date +%d | sed 's,^0,,g'`
if [ "$yest_dat_day" -lt 10 ]
then
        ls -ltr|grep " $yest_dat_mon  $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh
else
        ls -ltr|grep " $yest_dat_mon $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh
fi


yest_dat_day=`TZ=CST+24 date +%d | sed 's,^0,,g'` return "5" for me. So what is the significance of "$yest_dat_day" -lt 10 ??

Can you please explain?

Also i do not see any difference in the if else statements i.e.

then
ls -ltr|grep " $yest_dat_mon $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh
else
ls -ltr|grep " $yest_dat_mon $yest_dat_day "|grep "access"|awk '{print "cp -p "$9" /tmp/moht"}' | sh

Please let me know.

Last edited by shifahim; 09-06-2011 at 10:42 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep to fetch exact list

Hi I have below lists of files filename-1.0.0.tar.gz filename-1.0.1.345657676.snapshots.tar.gz so when I do grep -o 'filename-*.tar.gz' | sort | tail -1 then it consider snapshots as a part of it's result. How can I make sure, that it should only display the results from... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

2. Shell Programming and Scripting

Grep and ignore list from file

cat /tmp/i.txt '(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)' grep -ia 'ORA-\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt` grep: Unmatched ( or \( Please tell me why am i getting that (6 Replies)
Discussion started by: jhonnyrip
6 Replies

3. UNIX for Dummies Questions & Answers

Grep on a list

Hi, If I have a list called list.txt and on each line theres a string of the form something*blah, how do I remove everything after the * for each item? Thanks! (7 Replies)
Discussion started by: jyu429
7 Replies

4. Shell Programming and Scripting

grep a variable from list

I have a script to create a variable from a list, B.txt and then search it in another file, file.txt and then print the pattern line and next line. #!/bin/bash while read a do echo "$a" | grep -A 1 $a file.txt > $a\.txt done < B.txt I always get that no such file or directory exists... (6 Replies)
Discussion started by: godzilla07
6 Replies

5. UNIX for Dummies Questions & Answers

grep list of directories

Hi all, it possible creating a file with list of directories, and using grep to find pattern on only directories and subdirectories contained in that file? And it is done? regards (4 Replies)
Discussion started by: bspirit
4 Replies

6. Shell Programming and Scripting

Grep a files list

Hi, I want to grep a string from the list of files present in a text file. I want the output to be printed only when the string is present in a file along with the file name.. I tried some thing like cat files_list | grep "search_string" $_ I know $_ is wrong but i want something... (7 Replies)
Discussion started by: nigas
7 Replies

7. UNIX for Dummies Questions & Answers

How to Grep list of directories

I have multiple systems with each having its own log directory containing log file pertinent to that system. I have constructed a find/grep statement to get the list of directories ending in log, but I can't seem to pipe that to grep (via xargs) to have grep search each file in the log directories... (8 Replies)
Discussion started by: jmgibby
8 Replies

8. Shell Programming and Scripting

how to grep a file in list

hi all, for an example: In a file out.txt contains: /export/home/raghu/bin/debug_serverLog_apache_20090626_0625.txt How to grep or cut the value as "debug_serverLog_apache_20090626_0625.txt" or i want only the output as "debug_serverLog_apache_20090626_0625.txt" pls advice me (3 Replies)
Discussion started by: raghur77
3 Replies

9. Shell Programming and Scripting

grep a list of values

Hi everybody! :) :D :D :) it's great to be here since this is my first post. touch /base/oracle/FRA/XMUT00/RMAN_FLAG touch /base/oracle/FRA/XRLL00/RMAN_FLAG find directory name containing RMAN_FLAG : $ find /base/oracle/FRA -name RMAN_FLAG -print|xargs -n1 dirname |sort -u... (3 Replies)
Discussion started by: jolan_louve
3 Replies

10. UNIX for Dummies Questions & Answers

List grep results

Hi I need to search for matching strings in a database and I want to print out all files that matches in "detail", which means that I want the output to contain datum of last saving. I only get the grep function tp print the actual file names which is not enough since the database is to large... (14 Replies)
Discussion started by: slire
14 Replies
Login or Register to Ask a Question