I have a backup folder that has sub folders created daily. Each sub-folder contains files for that specific day. I need to search all those files to see which ones contains a specific phrase. I also need to take that phrase and output to a text file for that day. This can be done with a one liner, but due to space issues on the box, all the files are gzipped. So, I need to work with a days worth of files before moving the next day.
1. Find the files for say april 1st (this is in the file name as 110401)
3. Gunzip the files
4. Grep the files and send output to a text file
5. Gzip the files
6. Move on to the next day
I know how to find, gunzip, grep, redirect to another file, gzip the files. But how do I get it to do it per day?
After this, the script should go to the next day. How do I accomplish this?
---------- Post updated at 04:38 PM ---------- Previous update was at 11:17 AM ----------
I found that zgrep allows me to read into the gz file without having to uncompress it.
You mean like putting it into a loop? Try
The above will loop through all .gz files containing 1104 and two digits inside the dir1104* directories (please adjust to your particular dir structure); grep needs to be redirected with >> otherwise you'll have in the log only the matches of the last file; no need for find(1) in this construct. You can use 'grep -A3' to get 3 lines after the matched line. ${p%%.*} will substitute only the part of filename before the first period (in some modern shells).
I tried zgrep, but it only reports match/no match, and not the actual content matched....
--------------------------------
I just noticed you're not dealing with tarballs, just gzipped files... zgrep works fine there:
Last edited by mirni; 05-08-2011 at 12:49 AM..
Reason: tar comment
Hi guys and gals...
I am writing a piece of code that is dash compliant and came across this error.
I have put it in the OSX section as that is what I am using.
I have no idea what the 'dash' version is but was installed about 6 months ago.
MBP, OSX 10.12.6, default terminal running dash on... (4 Replies)
Hi,
i have csv input file looks like below
3rd field is date and time field i want to change it with user supplied date and time says
year=2011
month=09
day=05
hour=11
count=2
when count is say 10 then first ten records should pick and it should increment the... (2 Replies)
Hi everyone. Silly might be silly be I'm still new to bash. I'm trying to make an Alarm Clock for in the morning using my laptop i have wrote this Simple Script but i cant work out how to play it at a certain time.
#!/bin/bash
cd /home/josh/Music/Bruno_Mars/Hooligans/
cvlc... (8 Replies)
Hey guys. If I'm in a directory with only one directory, for example:
foo@bar:/$ ls
really-complicated-or-long-dir-name
Why wouldn't piping this single line of output into cd work?
foo@bar:/$ ls | cd
I'm just getting started with the shell and I was trying to navigate into a directory with a... (1 Reply)
hi all,
Ive been trying to find some way of doing this for ages but i have is a shell script that activates a python search and there it no tab completion. more familliar with tcsh at the moment but i'm a newbe.
i was trying to make an easy way to browse to a list of working directories.
... (0 Replies)
Hi,
I have set up sar on my RedHat and Fedora Linux systems. I am running sa1 from cron:
0 8-17 * * 1-5 /usr/lib/sa/sa1 1200 3 &
The 1200 and 3 parameters tell sa1 to save data every 1200 seconds (== 20 minutes) and to write 3 times.
When I run sar to observe my data, I'll see... (1 Reply)
Hi All
i want to write a script which could copy one file at a time from one directory to another directory.
Scenerio:
Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs.
please help me... (1 Reply)
How to get the current working directory as part of the command prompt? Every time I chage the folder, my command prompt path shoud change. I am using Korn Shell. Any help is greatly appreciated. (3 Replies)
Hi,
I have a problem with a Unix server we do not adminster but have an application running on.
The problem is that overnight, files in the /user4/work directory revert to root ownership. This causes problems as we cannot process the files.
1) What would be causing files to revert to root... (1 Reply)