The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Preventing whitespace to be a delimiter in a for loop (bash/sh) kkkoehne Shell Programming and Scripting 4 05-15-2009 11:20 AM
Preserving whitespace in a for loop s_becker Shell Programming and Scripting 7 03-26-2009 03:09 PM
Of bash and whitespace... lev_lafayette Shell Programming and Scripting 2 04-13-2008 09:44 PM
error in bash script 'if' loop DILEEP410 Shell Programming and Scripting 2 06-06-2007 09:04 AM
loop does not execute in bash script? fedora Shell Programming and Scripting 2 01-16-2007 12:38 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-05-2009
triplemaya triplemaya is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Whitespace in filenames in for loop in bash script

I'm trying to search all .odt files in a directory for a string in the text of the file.
I've found a bash script that works, except that it can't handle whitespace in the filenames.

Code:
#!/bin/bash

if [ $# -ne 1 ]; then
    echo "Usage: searchodt searchterm"
    exit 1
fi

for file in $(ls *.odt); do
    unzip -ca "$file" content.xml | zgrep -ql "$1"
    if [ $? -eq 0 ]; then
        echo "$file"
    fi
done

(Coutesy of [ubuntu] [SOLVED] Search multiple .odt files - Ubuntu Forums)
I've gone through a number of postings on this forum, but simple tricks like quotes, of any kind, don't work. Any quotes I put around

Code:
(ls *.odt)

or just

Code:
*.odt

stop it working completely



I found this code

Code:
find /path/to/some/where/ -name  "*.pdf"  | awk '{print $5}'| uniq -d |while read name ; do

in a thread here
Preserving whitespace in a for loop
which solves the problem in that context, but I don't see how to integrate it into the script.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0