Solved

Unix + Shell script

Posted on 2010-11-11
4
443 Views
Last Modified: 2012-05-10
The below are the some of list of gzip files. My requirement is i may select 1 or 2 or n no.of gzip files from below, that time all the data from selected files should export into a '.txt' file.
How to do that, with a single command how can I export multiples files data into a txt file...  pls help???

Ex:::
-rw-r--r-- 1 s2badm wasgrp  56495 Nov  7 04:00 tracer.err.20773.07Nov2010_040033.gz
-rw-r--r-- 1 s2badm wasgrp  52307 Nov  8 04:00 tracer.err.23354.08Nov2010_040025.gz
-rw-r--r-- 1 s2badm wasgrp  48857 Nov  8 04:00 tracer.err.20773.08Nov2010_040025.gz
-rw-r--r-- 1 s2badm wasgrp 325994 Nov  9 04:03 tracer.err.23354.09Nov2010_040308.gz
-rw-r--r-- 1 s2badm wasgrp 319670 Nov  9 04:03 tracer.err.20773.09Nov2010_040308.gz
-rw-r--r-- 1 s2badm wasgrp 292450 Nov 10 04:03 tracer.err.20773.10Nov2010_040357.gz
-rw-r--r-- 1 s2badm wasgrp 297237 Nov 10 04:03 tracer.err.23354.10Nov2010_040357.gz
-rw-r--r-- 1 s2badm wasgrp 288204 Nov 11 04:03 tracer.err.23354.11Nov2010_040324.gz
-rw-r--r-- 1 s2badm wasgrp 289533 Nov 11 04:03 tracer.err.20773.11Nov2010_040324.gz
-rw-r--r-- 1 s2badm wasgrp 302498 Nov 12 04:03 tracer.err.23354.12Nov2010_040346.gz
-rw-r--r-- 1 s2badm wasgrp 297098 Nov 12 04:03 tracer.err.20773.12Nov2010_040346.gz
0
Comment
Question by:Srinivasu_V
4 Comments
 
LVL 12

Accepted Solution

by:
larsrohr earned 250 total points
ID: 34117937
If your machine has the gzcat command available, how about:
  gzcat file1.gz file2.gz ... filen.gz > myoutputfile.txt

(If you don't have gzcat, try zcat; or just use gunzip -c)

Is this what you had in mind?
0
 
LVL 7

Assisted Solution

by:Hatrix76
Hatrix76 earned 250 total points
ID: 34119014
you can do something like that:

for file in tracer.err.23354.10Nov2010_040357.gz tracer.err.23354.12Nov2010_040346.gz; do echo $file |  sed -e 's/.*\.\([0-9]\{2\}[a-zA-Z]\{3\}.*\)\.gz/\1/' >> output.txt ; zcat $file >> output.txt ; done

for all files you put in the in clause it does this:
this extracts date and time from the filename
writes the date and time to output.txt
writes the content from this filename to output.txt

If I understood correctly you want this? Or did you mean another time to write into the output file?
best


0
 
LVL 12

Expert Comment

by:mccracky
ID: 34120962
Sounds a little like homework.  What do you have so far that we can help you with?
0
 

Author Closing Comment

by:Srinivasu_V
ID: 34222701
s
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to learn Linux? 10 61
Linux/Apache File Ownership/Permissions 1 65
linux redhat 7.2 10 75
how to install java on RHEL image on EC2 4 31
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question