![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|