Unix + Shell script

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

-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
Question by:Srinivasu_V
LVL 12

Accepted Solution

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?

Assisted Solution

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?

LVL 12

Expert Comment

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

Author Closing Comment

ID: 34222701

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now