LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2017, 07:46 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 223

Rep: Reputation: 8
can't get gunzip to work in bash script


The following bash script will not unzip my files.

They can be unzipped on the command line.

If I eliminate the final "| gunzip" the files are listed properly so they are being found and passed along to gunzip.


Code:
#!/bin/bash

folder="/home/rick/Desktop/mydb-bakup-folder2"
echo "-- Start .."

ls -d mydb-bakup-folder2/* | grep .gz  | gunzip
 
echo
echo -- Finish -
The Output is:

-- Start ..

gzip: stdin: not in gzip format

-- Finish --
 
Old 09-24-2017, 08:40 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,506
Blog Entries: 6

Rep: Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421
When you pipe into g{un}zip, it expects the compressed data from stdin, not the filename, so it complains that what it sees on stdin is not in gzip format.

You should try using find with the exec option instead. Something like this:

Code:
find path/to/search -type f -iname '*gz' -exec gunzip {} +
You can limit the depth of the search and file names as required. You may also need to escape the brackets and + (or ; ) depending on invocation context.

Last edited by astrogeek; 09-24-2017 at 08:53 PM. Reason: escaped ( or ;)
 
Old 09-24-2017, 10:58 PM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 223

Original Poster
Rep: Reputation: 8
Thanks astrogeek,

Works fine.

R
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to work on files don_wombat_73 Programming 4 11-22-2012 01:56 AM
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 01:05 AM
bash script sometimes work oscarenzo Linux - Newbie 6 04-16-2012 04:41 PM
[SOLVED] problem using gunzip within a script danishgambit Linux - Newbie 4 10-25-2011 06:41 AM
gunzip and ftp using a script @ a time shipon_97 Linux - Newbie 6 03-22-2009 02:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration