LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06:46 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
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, 07:40 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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 07:53 PM. Reason: escaped ( or ;)
 
Old 09-24-2017, 09:58 PM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thanks astrogeek,

Works fine.

R
 
  


Reply



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 12: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 12:05 AM
bash script sometimes work oscarenzo Linux - Newbie 6 04-16-2012 03:41 PM
[SOLVED] problem using gunzip within a script danishgambit Linux - Newbie 4 10-25-2011 05:41 AM
gunzip and ftp using a script @ a time shipon_97 Linux - Newbie 6 03-22-2009 01:24 PM

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

All times are GMT -5. The time now is 07:21 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
Open Source Consulting | Domain Registration