Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unix + Shell script

Posted on 2010-11-11
4
Medium Priority
?
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 12

Accepted Solution

by:
larsrohr earned 750 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 750 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
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 …
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…
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…
Suggested Courses

705 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