tar & Grep together


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar & Grep together
# 1  
Old 03-14-2007
tar & Grep together

Hi,

I've got dozens of tar's with two files in each one,
live_access_log & live_error_log (one tar for each day, backups).
The probelm is i need to match a pattern in all of the archive_access_log files and output the line to a seperate file (All_access.log).

I.e. I need to get details about each time a certain web page was accessed into one file that can be analysed using webtrends.

Some Files:

Code:
-rw-r--r--   1 root     root     23859712 Mar 14 14:59 apache_live_2007_02_28_1.tar
-rw-r--r--   1 root     root     22019584 Mar 14 14:59 apache_live_2007_03_01_1.tar
-rw-r--r--   1 root     root     17999872 Mar 14 14:59 apache_live_2007_03_02_1.tar
-rw-r--r--   1 root     root     15144448 Mar 14 14:59

I'm trying:

Code:
tar -xvf *tar | grep roaming.htm live_access_log > results.log

but to no avail. :-(


Any help would be greatly appreciated.

Last edited by tom123; 03-14-2007 at 01:00 PM..
# 2  
Old 03-14-2007
Code:
for file in *tar
do
    tar -xf $file && grep roaming.htm live_access_log > results.log
done

# 3  
Old 03-14-2007
Cool, thanks anbu23.
What sort of file should i put this code in? .sh?
And how should i execute it?
# 4  
Old 03-14-2007
tom.sh
Code:
for file in *tar
do
    tar -xf $file && grep roaming.htm live_access_log > results.log
done

Run from the command line as
Code:
./tom.sh

# 5  
Old 03-15-2007
Works Perfect anbu23 :-)

Just need to change it a little to first unzip the folder and then tar.
I have:

Code:
for zipped_folder in *tgz
do
  current_tar = 'gunzip $zipped_folder'
  tar -xf $current_tar && grep "GET roaming98.htm?98&htm" live_access_log > results.log
done

But it dos'nt work.
Any ideas?

Thanks in Advance
# 6  
Old 03-15-2007
Does the gzipped files contain tar files of same name?
If no then try this
Code:
gunzip *tgz
for file in *tar
do
    tar -xf $file && grep roaming.htm live_access_log > results.log
done

# 7  
Old 03-15-2007
Yet more problems!

I'm trying to check if there are any files in current directory to unzip.
If not, then it should exit.

Code:
# Make sure there are files to unzip
if [ ls -l *"$extension" | wc -l > 0 ] ; then
  echo "\nUnzipping files, please wait..."
  gunzip *"$extension"
else
  echo "\nThere are no files to unzip in this directory!\n\n"
  exit 0
fi

Following output is produced:

Code:
What is the zip file extension? (tgz, zip, etc...)
tgz
./results.sh: test: ] missing
wc: cannot open ]

There are no files to unzip in this directory!

It seems to work, but what is the test : ] missing all about?

Thanks In Advance
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep through a .tar file without untarring it

Hi All, I need to grep through a .tar file without untarring it. Would you please help me with that ? The extension to this request is to use the cut command to extract the data from a particular field. Appreciate your quick look around (8 Replies)
Discussion started by: sanjaydubey2006
8 Replies

2. AIX

AIX & TAR related stuff

This thread is about using tar & other compression utilities on AIX ; 1. Find out which version of tar you are using thanks to bakunin >what $(which tar) /usr/bin/tar: 61 1.14 src/bos/usr/ccs/lib/libc/__threads_init.c, libcthrd, bos53 0 7/11/00 12:04:14 10 ... (21 Replies)
Discussion started by: filosophizer
21 Replies

3. Shell Programming and Scripting

help with tar & zip only last months(say,Sep) files

Need to 1. archive all the files in a directory from the previous month into a tar/gz file, ignoring all already archived 'tar.gz' files 2. Check created .tar.gz file isnt corrupted and has all the required files in it. and then remove the original files. I am using a function to get the... (1 Reply)
Discussion started by: Prev
1 Replies

4. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

5. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

6. Solaris

Tar & Tape drive without media

Hi all, I would like to know what would happen if the tape (media) is not placed on the drive and a tar command is executed to backup on the tape. My problem is that tar command hanged for multiple days instead of throwing the error, Is it valid behaviour? I was unable to test the... (4 Replies)
Discussion started by: jmsathish
4 Replies

7. Shell Programming and Scripting

Script for tar and zip based on month & year

Hi Friends, I'm doing on script which finds all the files with time stamp and makes them tar and zip, based on their respective month&year. for instance "mar-2004.tar.zip" will contain all the files which was created/accessed/modified on mar-2004. like this the entire filesystem should be taken... (1 Reply)
Discussion started by: tuxfello
1 Replies

8. UNIX for Advanced & Expert Users

grep for a tar File

Hello, I made a tar with a lot of file, and i deleted all the Files. So to win tile I want to make a grep of this tar file to search any text . Is there a Unix command available for this ? I tried : grep xyz file.tar but there is nothing . Thanks for your help.... (1 Reply)
Discussion started by: steiner
1 Replies

9. UNIX for Dummies Questions & Answers

disaster recover w/tar & find

Hi, I am creating a disaster recovery plan for my Linux 7.2 machine. I have two backups from my current machine. One created using the command tar -cvpf /dev/st0 --exclude=/proc --directory / . and one created with the command find / /boot /home -mount -path '/proc' -prune -o -print |... (4 Replies)
Discussion started by: jeremiebarber
4 Replies

10. Shell Programming and Scripting

Find & tar execution problem

I'm trying to set up a stanard sh script that will find all the files that have been changed within the last day and then tar them up. I think the command line should be something like : find /home/bob -atime +0 -exec \ tar cvf /home/bob/files.tar {}\; Help please ... Thanx (3 Replies)
Discussion started by: ianf
3 Replies
Login or Register to Ask a Question