Solved

Unix + Shell script

Posted on 2010-11-11
4
434 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now