Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2006
    Posts
    9

    Exclamation Unanswered: Unix Shell - Dir and Files with Space

    Iam having Problems while loooping Through a Find Command ( for i in `find "$3" -name "*.*" -print 2>/dev/null` do done ) which returns Files and Dirs with Space In between.

    It Breaks a Single Output from the find Command into two when it encounters a Space.

    Example : Iam having a Dir by Name "test dir" which has two file

    -rw-r--r-- 1 240 203 22 Dec 11 13:00 test1
    -rw-r--r-- 1 240 203 22 Dec 11 13:00 test1 kk.txt

    When I run this Script .....

    dir_v="./test dir"
    for i in `find "$dir_v" -name "*" -print 2>/dev/null`
    do
    echo "$i"
    done

    ........ I get this Out put.

    ./test
    dir
    ./test
    dir/test1
    ./test
    dir/test1
    kk.txt

    Notice how the output breaks into the next line when it encounters a Space.
    How do i get around this issue ? ... Please Help!!!!

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    "for" reads space delimited arguments, set IFS=
    Code:
         IFS  The Internal Field Separator  that  is  used  for  word
              splitting after expansion and to split lines into words
              with the read builtin command.  The  default  value  is
              ``<space><tab><newline>''.
    i.e.
    Code:
    dir_v="./test dir"
    IFS=
    for i in `find "$dir_v" -name "*" -print 2>/dev/null`
    do 
      echo "$i"
    done
    But what are you trying to do?
    Maybe you don't need the "for"
    just use -exec with the find command

  3. #3
    Join Date
    Nov 2006
    Posts
    9

    Question Thanks pdreyer ....

    This is a File search /FTP Program called from Oracle ...I need Individual File names for Updating some information Back to Oracle and Hence iam using the Looping Structure.
    Thanks so Much ...I will try this and Let you know.
    Last edited by ksundararajan; 12-12-06 at 11:17.

  4. #4
    Join Date
    Nov 2006
    Posts
    9

    Question Another Problem

    when I do IFS=\n its gives the Output in a Single Line
    ........
    IFS=\n
    for i in `find "$3" -name "*.*" -print 2>/dev/null`
    do
    Origfile=`basename $i `
    if excludePrc $Origfile; then
    echo "Copying $i"
    cp "$i" "$4"
    fi
    done
    IFS=$oldIFS

  5. #5
    Join Date
    Nov 2006
    Posts
    9

    Option 2 : Find Exclude *.pdc and CP

    I will try to avoid Looping ...
    Last edited by ksundararajan; 12-12-06 at 14:38.

  6. #6
    Join Date
    Nov 2006
    Posts
    9
    Quote Originally Posted by pdreyer
    "for" reads space delimited arguments, set IFS=
    But what are you trying to do?
    Maybe you don't need the "for"
    just use -exec with the find command
    ok... I can use this Comand to exclude *.pdc files ....

    find "$pth" ! -name "*.pdc" -exec cp {} . \; 2>/dev/null

    ....But How do i avoid Directories ? ..Though CP doesn't copy directory I still get a Error message ...How do I avoid this ?

  7. #7
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Code:
    find "$pth" -type f ! -name "*.pdc" -exec cp {} . \; 2>/dev/null

  8. #8
    Join Date
    Nov 2006
    Posts
    9

    Thats Works ....But Multiple Excludes in a Single Find Command

    Yes that works for me .....Thanks!!!!

    But how do i include Multiple Excludes in a Single Find Command.....
    Just like i have excluded *.prc , what if i want to extend this to Other extensions also???


  9. #9
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Code:
    find "$pth" -type f ! \( -name "*.pdc" -o -name "*.prc" \) -exec cp {} . \; 2>/dev/null
    or
    Code:
    find "$pth" -type f ! -name "*.p[dr]c" -exec cp {} . \; 2>/dev/null

  10. #10
    Join Date
    Nov 2006
    Posts
    9

    Thanks .... That works!!!

    Thanks .... That works!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •