LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-26-2012, 04:51 AM   #1
gajananh999
Member
 
Registered: Aug 2012
Posts: 94

Rep: Reputation: Disabled
Not able to extract files.


Dear All,

i want to extract all the files from one folder and the all fine name contains space in it so it is not able to extract the files

Code:
#!/bin/bash
FILES=/logs/isac/collation/data/server1/*.7z
for f in $FILES
do
  echo "Processing $f file..."
7za u -o/logs/isac/collation/data/logs1/ "$f"
done
and the file names are like

AEPLWEB1-Server - Copy_H20121026-070000464.log.7z
AEPLWEB1-Server - Copy_H20121026-060000462.log.7z
 
Old 10-26-2012, 05:14 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try this http://mywiki.wooledge.org/BashFAQ/001
 
Old 10-26-2012, 05:15 AM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
try:
Code:
while read
do
    7za u -o/logs/isac/collation/data/logs1/ "$REPLY"
done < <(find /logs/isac/collation/data/server1 -iname "*.7z")
 
Old 10-28-2012, 03:20 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
chrism01's link is for reading text from a file and operating on the contents. That's not what the OP asked for.

And Keith's is really just a variation of the same technique, only it uses the input from find as the text source, and runs the commands on that list. It will probably work, unless the filenames themselves actually contain newlines, but I see nothing there that simple globbing can't handle already (and I would simply use find's -exec option instead of the loop anyway).


In fact, the OP's code should work just fine as it stands, as far as I can tell, and indeed I would've given pretty much that exact solution. The variable contains a globbing pattern which would expand when the for loop is executed, which it should be able to read correctly and run the sub-commands on.

The only way I can see it failing is if the "$f" variable were not quoted in the subcommands (which would allow word-breaking on the contents), or if "$FILES" was quoted in the outside loop (in which case the content would be seen as a single entry, an unexpanded glob). But the loop as posted doesn't show either of those errors.

If the posted loop is indeed the exact command that was run, then the OP needs to explain in exactly what way it's not working. What errors or output are you actually getting?

Last edited by David the H.; 10-28-2012 at 03:25 PM.
 
Old 10-29-2012, 09:45 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I think the OP is not clear enough for me to provide a solution.

To extract all 7zips in a directory you can let 7zip handle it:

Code:
7z x '*.7z'
But, I'm not sure that this is what the OP wants. I'm not sure anyone can be sure until a more concrete example and explanation are provided.
 
  


Reply

Tags
extract, space



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
[SOLVED] extract text from files Frakk Programming 17 08-29-2010 04:28 AM
How can I extract only *.c files from a tar.gz? [KIA]aze Linux - Newbie 7 06-06-2007 04:39 AM
How do I extract files from .daa files under linux? izquierdista Linux - Software 8 04-09-2007 09:37 PM
extract files ust Linux - General 1 08-05-2005 01:16 AM
how to extract .0xx files? provkitir Linux - Software 3 04-19-2005 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:57 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