Sponsored Content
Full Discussion: Insidious Space
Top Forums Shell Programming and Scripting Insidious Space Post 302263503 by varontron on Monday 1st of December 2008 07:03:27 PM
Old 12-01-2008
Insidious Space

Hi,

My ksh script generates a pattern list and a directory list and then iterates over each directory to grep for the pattern in each file in each directory.

The script uses find to output a directory list, which is preprocessed to escape spaces before continuing.
It then calls a function, which calls grep inside a while loop.
The call to grep appends a * to each directory path to find the pattern in each file in the directory.

The problem is that some of my directory names contain space characters.

grep fails on these. Depending on quoting, escaping, etc, I get either "cannot open" or wordsplitting on the pathname. The script works beautifully on paths without spaces.

I have tried every way of quoting, escaping etc I can think of. I've tried setting IFS=''.

Curiously, the function does not appear to recognize my path either, and I've been forced to use absolute paths for utility calls (i.e. /usr/bin/awk,) but only in the function.

Here are excerpts of code:

Code:
#!/bin/ksh

PATH=/usr/bin
export PATH

function procfile
{
SEARCH=$1
PATTERNFILE=$2
OUTPUTFILE=$3
TEMPFILE=/tmp/output_$$.tmp
OWNER=
OBJECT=

# escape spaces in paths
SEARCHFILE=`echo "$SEARCH"|/usr/bin/sed 's/ /\\\ /g'`

/usr/bin/cat ${PATTERNFILE} | while read LINE
do
  OBJECT=`echo ${LINE}|/usr/bin/awk -F, '{ print $2 }'`
  # find refs to the pattern in each of the files
  /usr/bin/grep -in "[^a-zA-Z0-9_]${OBJECT}[^a-zA-Z0-9_]" "$SEARCHFILE"/* > ${TEMPFILE}
  # iterate over the result to marry the pattern to the result in tabular format
  /usr/bin/cat ${TEMPFILE} | while read LINE2
  do
 
    # do query
    ${ORACLE_HOME}/bin/sqlplus -s...
  done
done
}

INPUT=dirlist.txt
PATTERN=oracle_objects.txt
OUTPUT=output.txt

# Query for current patternlist
${ORACLE_HOME}/bin/sqlplus ...

# Prepare the directory list
find ...
# escape spaces in paths
sed 's/ /\\\ /g' /tmp/dirlist.txt > dirlist.txt

# iterate over dirlist
cat ${INPUT} | while read LINE
do
    COUNT=`ls -l "$LINE"|wc -l`
    if [ ${COUNT} -gt 1 ]
    then
      procfile "$LINE" ${PATTERN} ${OUTPUT}
    fi
done

Any insight you can provide will be most helpful.

Thanks,
Dave
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

wake up user space thread from kernel space ISR

Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt. Except for sending a real-time signal, is it possible to use a semaphore? I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies

2. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

3. Shell Programming and Scripting

Stripping out more than a space from a line, but keep single space.

Hi all, Is there a way to perform the above, I am trying to strip out more than one space from a line, but keep the single space. See below output example. My Name is test test2 test3 test4 test5 My Name is test test2 test3 test4 test5 Please note that the lines would contain... (7 Replies)
Discussion started by: eo29
7 Replies

4. Linux

How to reclaim the space which i used to increse the swap space on Xen,

Hi, i have done a blunder here, i increased the swap space on Xen5.6 server machine using below steps :- 1056 dd if=/dev/zero of=/root/myswapfile bs=1M count=1024 1057 ls -l /root/myswapfile 1058 chmod 600 /root/myswapfile 1059 mkswap /root/myswapfile 1060 swapon /root/myswapfile ... (1 Reply)
Discussion started by: apm
1 Replies

5. Solaris

No space left on device but free space and inodes are available...

hi guys, me again ;) i recently opened a thread about physical to zone migration. My zone is mounted over a "bigger" LUN (500GB) and step is now to move the old files, from the physical server, to my zone. We are talking about 22mio of files. i used rsync to do that and every time at... (8 Replies)
Discussion started by: beta17
8 Replies

6. Fedora

Need to incrwase PHYSICAL VOLUME space on hard drive with free space on it

Hi, I run Fedora 17. I created a physical volume of 30GB on a disk with 60GB of space so there is 30GB of free space. On the physical volume, I created my volume group and logical volumes. I assigned all the space in the physical volume to my volume group. I need to add the 30GB of free space... (1 Reply)
Discussion started by: mojoman
1 Replies

7. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

8. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

9. Linux

No space left on device while there is plenty of space available

Hello all posting here after scanning the net and tried most of the things offered still no solution that worked when I do : $ df -h Filesystem Size Used Avail Use% Mounted on footmpfs 7.9G 60K 7.9G 1% /dev tmpfs 7.9G 0 7.9G 0% /dev/shm /dev/da1 ... (3 Replies)
Discussion started by: umen
3 Replies

10. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies
Courier::Config(3pm)					User Contributed Perl Documentation				      Courier::Config(3pm)

NAME
Courier::Config - Class providing configuration information for Perl modules related to the Courier MTA SYNOPSIS
use Courier::Config; # Courier base configuration: my $config_dir = Courier::Config->config_dir; my $runtime_dir = Courier::Config->runtime_dir; my $courier_executable = Courier::Config->courier_executable; my $courier_version = Courier::Config->courier_version; # Courier::Filter configuration: my $filter_conf_file = Courier::Config->filter_conf_file; DESCRIPTION
This class provides configuration information for Perl modules related to the Courier MTA, e.g. installation specific file system paths. Courier base configuration The following methods provide information about Courier's base configuration: config_dir: returns string The base configuration directory of Courier. runtime_dir: returns string The directory where Courier keeps the message queue ("msgq", "msgs", "tmp") and courierfilter sockets ("filters", "allfilters"). courier_executable: returns string The full path of the Courier daemon executable. courier_version: returns version The version number of the Courier installation. Courier::Filter configuration The following Courier::Filter configuration information is provided: filter_conf_file: returns string The absolute file name of the Courier::Filter courier-filter-perl configuration file. SEE ALSO
For AVAILABILITY, SUPPORT, and LICENSE information, see Courier::Filter::Overview. AUTHOR
Julian Mehnle <julian@mehnle.net> perl v5.14.2 2011-12-27 Courier::Config(3pm)
All times are GMT -4. The time now is 03:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy