Sponsored Content
Top Forums Shell Programming and Scripting Whitespace in filenames in for loop in bash script Post 302313271 by triplemaya on Tuesday 5th of May 2009 08:08:54 AM
Old 05-05-2009
Thank you very much, I never thought of just taking that out!

For the completeness of this thread in case others are interested it has also been pointed out by someone on the other thread that all the way over on page *2* of the referenced thread there is a working script for this purpose, which also takes the path as command line arg. Smilie

Code:
#!/bin/bash

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

find $1 -name "*.odt" | while read file
do
        unzip -ca "$file" content.xml | grep -qli "$2"
        if [ $? -eq 0 ]; then
                echo "Found keyword in: " $file
        fi

done
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

while read loop preserving leading whitespace

Hi all, I've been trying to get this to work for ages to no avail. I've searched this site and googled but cannot find a satisfactory answer. I've got a while loop, like this while read line do echo "$line" done < file_name Now, my problem is that most of the lines in the file... (3 Replies)
Discussion started by: zazzybob
3 Replies

2. Shell Programming and Scripting

Of bash and whitespace...

Hmmm... Bash doesn't parse whitespace with a read. lev@sys09:~$ read line; echo "$line" test test You can imagine what this does if you're using a shell script to read a list of unknown file names containing unknown spaces. lev@sys09:~$ read word1 word2; echo "$word1,$word2" 123 456... (2 Replies)
Discussion started by: lev_lafayette
2 Replies

3. Shell Programming and Scripting

Preserving whitespace in a for loop

I obviously haven't learned my lesson with shell and whitespace. find /path/to/some/where/ -name "*.pdf" | awk '{print $5}'| uniq -d results: some Corporation other Corporate junk firmx Works fine from cmdline but the whitespace turns into another FS in a for loop. for... (7 Replies)
Discussion started by: s_becker
7 Replies

4. Shell Programming and Scripting

Preventing whitespace to be a delimiter in a for loop (bash/sh)

Hi, I have a for loop which iterates over a list of strings, separated by whitespace: $ list="1 2 3" $ for i in $list; do echo $i; done 1 2 3 I now want to introduce some strings containing whitespace themselves ... This is straightforward if I directly iterate over the list: $ for... (4 Replies)
Discussion started by: kkkoehne
4 Replies

5. Shell Programming and Scripting

Bash script - stripping away characters that can't be used in filenames

I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out. My thought was to use 'tr' with but the result is the opposite of what I want: $ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies

6. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

7. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies

8. Shell Programming and Scripting

Expect script called in loop from Bash Script

Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass). Here is... (0 Replies)
Discussion started by: cbo0485
0 Replies

9. Shell Programming and Scripting

REGEX to separate paths by whitespace and do a loop

I am trying to do in a single line to take a list of paths separated by whitespace and then loop thru all the paths that were wrote but my regex is not working, I have echo {3} | sed 's/ //g' | while read EACHFILE do ..... But for some reason is only taking always the first path that I... (7 Replies)
Discussion started by: jorgejac
7 Replies

10. UNIX for Beginners Questions & Answers

Help with a bash loop script

Create a single bash script that does the following: a. Print out the number of occurrences for each motif that is found in the bacterial genome and output to a file called motif_count.txt b. Create a fasta file for each motif (so 3 in total) which contains all of the genes and their... (6 Replies)
Discussion started by: dre
6 Replies
PTHREAD_GETNAME_NP(3)					   BSD Library Functions Manual 				     PTHREAD_GETNAME_NP(3)

NAME
pthread_getname_np -- get and set descriptive name of a thread LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread.h> int pthread_getname_np(pthread_t thread, char *name, size_t len); int pthread_setname_np(pthread_t thread, const char *name, void *arg); DESCRIPTION
The pthread_getname_np() function obtains the descriptive name of a thread. It takes the following arguments: thread The thread whose descriptive name will be obtained. name The buffer to be filled with the descriptive name of the thread. len The size of the buffer name in bytes. The pthread_setname_np() function sets the descriptive name of a thread. It takes the following arguments: thread The thread whose descriptive name will be set. name The printf(3) format string to be used to construct the descriptive name of the thread. The resulted descriptive name should be shorter than PTHREAD_MAX_NAMELEN_NP. arg The printf(3) argument used with name. RETURN VALUES
Both functions return 0 on success. Otherwise, an error number is returned to indicate the error. COMPATIBILITY
Both functions are non-standard extensions. ERRORS
Both functions may fail if: [EINVAL] Invalid parameter. [ESRCH] Non-existent thread. The pthread_setname_np() function may also fail if: [ENOMEM] There was insufficient memory for the operation. SEE ALSO
pthread_attr_get_np(3), pthread_attr_getname_np(3) BSD
July 9, 2010 BSD
All times are GMT -4. The time now is 10:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy