[solved] recursive bulkrenaming

Hi, I have been using a renaming script from brisbin33, he was posting in "Handy self made command line utilities".
#!/bin/bash
# pbrisbin 2009
# take a retardedly named file or directory and rename it
# sanely
# adjust translate() as needed
message() { echo 'usage: renamer (--fake) <target> ...'; exit 1; }
# could always use more shit here...
translate() {
tr -d '\n' | tr -d '\t' | tr -d \' | tr -d \" |\
sed -r -e 's/.*/\L&/g' \
-e 's/[ -]/_/g' \
-e 's/_+/_/g' \
-e 's/^_|_$//g' \
-e 's/ä/ae/g' \
-e 's/ö/oe/g' \
-e 's/ü/ue/g' \
-e 's/ß/ss/g'
rfile() {
local dir old new
dir="$(dirname "$1")"
old="$(basename "$1")"
new="$(echo $old | translate)"
if [[ "$old" != "$new" ]]; then
if $fake; then
echo "$dir/$old --> $dir/$new"
else
mv -iv "$dir/$old" "$dir/$new"
fi
fi
rdir() {
local dir
while IFS='' read -d '' -r dir; do
rfile "$dir"
done < <(find "$1" -depth -print0)
[[ -z "$*" ]] && message
# allow a pretend run
if [[ "$1" = '--fake' ]]; then
fake=true
shift
else
fake=false
fi
# do it to it
for arg in "$@"; do
if [[ -d "$arg" ]]; then
rdir "$arg"
elif [[ -e "$arg" ]]; then
rfile "$arg"
else
message
fi
done
It saved me years of lifetime...but I still have one problem with it. When there is a name collision (a file with that name already exists and the script can't proceed therefore) the script just stops. I would prefer it, if the script could rename the file anyways, but append a number to get a unique filename (img.jpg => img02.jpg). Then I could do the cleanup later.
Sadly my scriptingskills are almost nonexistent. I am not even sure, if I have to implement that logic in the rfile-/rdir-functions or in the "do it" part of the script. As I have absolutely no clue, a little help would be much appreciated.
Thanks.
Last edited by inknoir (2011-05-08 17:48:05)

rfile() {
local dir old new
dir="$(dirname "$1")"
old="$(basename "$1")"
new="$(echo $old | translate)"
local i=1
while [[ -e "$new" ]]; do
let i++
new="${new}_$i"
done
if [[ "$old" != "$new" ]]; then
if $fake; then
echo "$dir/$old --> $dir/$new"
else
mv -iv "$dir/$old" "$dir/$new"
fi
fi
This seems to work.
Sorry, I should have posted the whole function before ;-)
// Edit: I only tested it with one file at first; Now i noticed my mistake
rfile() {
local dir old new
dir="$(dirname "$1")"
old="$(basename "$1")"
new="$(echo $old | translate)"
if [[ "$old" != "$new" ]]; then
if [[ -e "$new" ]]; then
local i=1
while [[ -e "${new}_$i" ]]; do
let i++
done
new="${new}_$i"
fi
if $fake; then
echo "$dir/$old --> $dir/$new"
else
mv -iv "$dir/$old" "$dir/$new"
fi
fi
This time it should be correct ...
Sorry again.
Last edited by MrX (2011-05-01 14:47:44)

Similar Messages

  • Need help solving recursion in workflow

    Here is the workflow, which kicks off automatically when a list item is changed. ULS logs report recursion occurring. I don't see where. I assume because oldmodifiedtime field is being updated, but I would think the Stop workflow action would prevent
    looping.
    Step 1
    If Current Item:Case Status equals Closed
      Stop the workflow and log Workflow stopped because case status is closed
    Else if Current Item:OldModifiedTime is less than Current Item:Modified
    and Current Item:Modified By equals Current Item:Requester
    and Current Item:EMailed Assigned equals Yes
      Email AAC IT Distribution
      then Set OldModifiedTime to Current Item:Modified
      then Stop the workflow and log Requester updated case
    Else if Current Item:OldModifiedTime is less than Current Item:Modified
    and Current Item:Assigned To contains Current Item:Modified By
    and Current Item:EMailed Assigned equals Yes
      Email Current Item:Reguester
      then Set OldModifiedTime to Current Item:Modified
      then Stop the workflow and log IT updated case
    (Note: the last line Stop workflow goes with last Else clause, it just pasted here spaced down and I can't seem to get rid of the extra line spacing.)
    Can anyone help with a resolution?
    Thanks,
    Joan

    Two errors:
    AutoStart Workflow: Microsoft.SharePoint.SPException: Recursive workflows are not permitted.     at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.<>c__DisplayClass1.<AutoStartWorkflow>b__0(SPSite superUserSite,
    SPWeb superUserWeb)
    WinWF Internal Error, terminating workflow Id# 8c200992-8b03-4533-8cc1-e66f4472794a
    The Id# matches with the history list. Also spot checked other times, different list items. Same errors, matching with history list.
    No errors in UI. No one who updates an item (user or IT) reports error. When I tried to run Cancellation & Error report in UI, I get Error, report contains no data. Return to site.
    Thanks,
    Joan

  • [SOLVED]Recursively use makepkg with python...or bash!

    I am basically trying to build a base Archlinux system from scratch on my eee pc. I researched Pacbuild a little bit but decided to try my own had at this.
    After being completely unsuccessful at trying to write bash scripts with loops and variables and whatnot, I took a look at python. I basically just searched a bunch of python tutorials on google and came up with this. So..this being my first script and all I was wondering if this would be the right way to do this. It basically works except with no error checking and if I want it to stop i have to press ctrl-c until the loop ends...but other that it works fine.
    #! /usr/bin/env python
    #import bash commands
    import os
    import sys
    #open pkglist file
    pkglist = open('/home/rhune/list', 'r')
    pkgname = pkglist.readline() #read pkgname in file
    while len(pkgname) != 0:
    pkgname = pkgname.rstrip('\n') #delete newline
    os.chdir('/home/rhune/eeepkgs')
    os.chdir(pkgname) #cd /home/rhune/pkgname
    os.system('makepkg') #run makepkg in working dir
    os.chdir('/home/rhune/eeepkgs') #cd ../
    pkgname = pkglist.readline() #read pkgname in file
    pkglist.close() #close file
    The "list" file is a list of folders in the directory im pointing to.
    I also plan on having it accept an argument of what folder to run in and using the tempfile to create the directory list, and with some sort of error checking. But thats a whole nother project.
    Any comments or contributions appreciated!
    edit: is there a way to check if makepkg successfully compiles the package? i.e. does it return a 1 or 0 or some sort of value? Or would i have to parse the actual output of it?
    Last edited by rhune (2009-08-28 04:48:05)

    Thanks much! This works, just gotta pick a better place to store the output.
    #!/bin/bash
    cd $1
    for folder in $(find * -type d)
    do
    cd $folder
    makepkg -s
    if [ $? -gt 0 ]; then
    echo $folder >> '/home/rhune/failed'
    else
    echo $folder >> '/home/rhune/passed'
    fi
    cd ../
    done
    Also figured out this in python:
    !/usr/bin/env python
    import os
    import subprocess
    base = "/home/rhune/test/pkgs"
    failed=[]
    dir = os.listdir(base)
    dir.sort()
    os.chdir(base)
    print dir
    for x in range(len(dir)):
    os.chdir(dir[x])
    retcode = subprocess.call(['makepkg', '-s'])
    if retcode==1:
    failed.append(dir[x])
    os.chdir(base)
    print failed
    The bash one seems a bit simpler though.
    Also, this:
    #! /usr/bin/env python
    import os
    import sys
    deplist=[]
    depname=""
    count=0 #count apostrophes
    #search for depends= line in pkgbuild
    with open('/home/rhune/pkgs/yaourt/PKGBUILD', 'r') as pkg:
    for deps in pkg:
    if "depends" in deps: break
    deps=deps.strip('depends=')
    #insert depnames into deplist
    for x in deps:
    if x=="'": count+=1 #counts apostrophes
    if x.isalpha(): depname+=x
    if count==2:
    deplist.append(depname)
    depname="" #reset depname
    count=0 #reset count
    #pbget for each dependency in list
    for x in range(len(deplist)):
    os.system('pbget --arch=i686 '+deplist[x])
    Reads a PKGBUILD file and pbgets dependencies. Need to change sys to subprocess, didnt realize it was outdated. Still needs a little work, but its practically done. Also made a sed script to go through each directory and change the PKGBUILD to use gcc-4.5 for the atom optimization.
    #!/bin/bash
    cd $1
    ls -l
    for folder in $(find * -type d)
    do
    cd $folder
    sed -s 's/\.\/configure/CC=gcc-4.5 \.\/configure/' PKGBUILD > tmpfile ; mv tmpfile PKGBUILD
    cd ../
    done
    These being the first time ever writing any sort of scripts, i think im getting the hang of it. Thanks to a little (and i mean little) bit of c++ knowledge.
    So im basically ready to compile the whole system, hopefully itll all work!
    Thanks
    edit: also, maybe a stupid question, but why does $0 -gt 0 work? does the script return a 1 or 0 after each iteration or is it from makepkg?
    Last edited by rhune (2009-08-28 04:53:52)

  • [SOLVED] Delete recursively all files with certain extensions

    Hi all,
    I am trying to recursively delete files with specific extensions. Many of these files have names containing spaces. The following, that I found googling around, didn't work:
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx' | rm
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx' -type f -ok rm '{}' ';'
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx' -exec rm -f '{}' \;
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx'| xargs /bin/rm -f
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx' -exec /bin/rm -f '{}' \;
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx'| xargs -0 rm
    and I think that it was the following that deleted all the files (except the directories):
    find /media/TSUNAMI -name '*out' -or -name '*aux' -or -name '*log' -or -name '*.blg' -or -name '*.toc' -or -name '*.bcf' -or -name '*.swp' -or -name '*blx' -type f -delete
    What am I doing wrong here?
    Thanks a lot in advance.
    PS. While writing this I realized that I fogot the dot in out, aux, log, and blx
    PS2. I'm experimenting around and don't mind deleting all the files if I do a mistake
    Last edited by geo909 (2014-09-30 06:12:04)

    geo909 wrote:Thanks so much. So  what is different when we group those options with \( \)?
    The implicit "and" operator binds stronger than the "or" (-o) operator. Therefore
    | -name a -o -name b -delete |
    will be grouped like this: 
    | (-name a) -o ( -name b -delete ) | .
    You want to group it like this: 
    | ((-name a ) -o ( -name b )) ( -delete )   | ,
    so you need to add some manual grouping: 
    | ( -name a -o -name b ) -delete |
    Last edited by progandy (2014-09-30 05:52:29)

  • Firefox 3.6 when I open a SWF file, a wrong mouse click, it show a recursive open window until the PC resource is used up or the system hang up, I try to reinstall firefox but not solved.

    Windows XP SP3, flash player 10.2, Shockwave 11.5.9.240 , when I open a SWF file with firefox 3.6.15, it shows some options to choose action and I made a wrong click. The firefox nightmare is a "open recursive windows" until the system hang. When I use Internet Explorer 8 to open it, it is fine, Try to uninstall firefox and reinstall it, but in vain, how can I restore it?

    You don't have the Shockwave Flash Player installed for Firefox. You may have the ActiveX version installed for IE, but Firefox needs the Plugin version. And Shockwave 11.5.9.240 that is installed for Firefox isn't the same thing.
    1.Download the Flash setup file from here: <br />
    [http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player.exe Adobe Flash - Plugin version]. <br />
    ''Or maybe get the previous '''r102''' version from here. IMO, there's problems with the latest version of Flash.'' <br />
    http://kb2.adobe.com/cps/142/tn_14266.html <br />
    Save it to your Desktop.<br />
    2. Close Firefox using File > Exit <br />
    then check the Task Manager > Processes tab to make sure '''firefox.exe''' is closed, <br />
    {XP: Ctrl+Alt+Del, Vista: Shift+Ctrl+ESC = Processes tab}
    3. Then run the Flash setup file from your Desktop.
    * On Vista and Windows 7 you may need to run the plugin installer as Administrator by starting the installer via the right-click context menu if you do not get an UAC prompt to ask for permission to continue (i.e nothing seems to happen). <br />
    See this: <br />
    [http://vistasupport.mvps.org/run_as_administrator.htm]

  • [solved] PCRE recursive replacing

    Hi all,
    I have tried to understand PCRE but am ATM busy untying the knot in my brain. Maybe someone of you is so proficient the he/she can point to a solution easily.
    I want to use PHP's preg_replace to replace some bbcode with valid html, but want to handle nested bbcodes.
    Example:
    This is [ i ]some text in [ i ]italics[ /i ] that has [ i ]italics even [ i ]inside[ /i ] of itself[ /i ][ /i ] so it can be a mess.
    (with spaces so it doesn't get formatted by the forum software here.)
    What I want my html do is switch between '<span style="font-style: italic;">' and '<span style="font-style: normal;">'. I suppose with those spans I can use nesting in turn, so I don't need to </span> before switching, provided that I deliver the closing </span> where the closing bbtag is. But with all those recursions and lookaheads, let alone replacing, the resources I could find got me lost.
    Up to now (before me messing with it), the actual code looks like this:
    $pattern = array(
    "/\[i\](.*?)\[\/i\]/si",
    $change = array(
    "<span style=\"font-style: italic;\">$1</span>",
    $string = preg_replace($pattern, $change, $string);
    Any ideas? TIA,
    Andreas
    Last edited by awagner (2008-04-24 21:23:39)

    im pretty sure that regex pattern can be improved, but i don't know enough to help;
    but you did mention that it's slow, so i thought maybe regex wasn't necessary since you're only matching and
    <?php
    $str= 'This is [i]some text in [i]italics[/i] that has [i]italics even [i]inside[/i] of itself[/i][/i] so it can be a mess.';
    function clock($t)
    return sprintf('%f', round(microtime(TRUE) - $t, 6));
    echo "$str<br /><br />\n\n";
    class MYCLASS
    var $currentlyItalics;
    function bbToHtmlItalics($input)
    $regex = '#\[i]((?:[^[]|\[(?!/?i])|(?R))+)\[/i]#';
    if (is_array($input)) {
    if($this->currentlyItalics) {
    $input = '<span style="font-style: italic;">'.$input[1].'</span>';
    } else {
    $input = '<span style="font-style:normal;">'.$input[1].'</span>';
    if(preg_match($regex, $input)) $this->currentlyItalics = !($this->currentlyItalics);
    return preg_replace_callback($regex, array(&$this, 'bbToHtmlItalics'), $input);
    function altbb($str)
    $alt = FALSE;
    $out = '';
    $tks = explode('[i]', $str);
    $end = array_pop($tks);
    foreach ($tks as $tok) {
    if ($alt) {
    $sub = 'italic';
    } else {
    $sub = 'normal';
    $out .= "$tok<span style='font-style:$sub;'>";
    $alt = !$alt;
    return str_ireplace('[/i]', '</span>', $out.$end);
    $bb = new MYCLASS();
    $t = microtime(TRUE);
    echo $bb->bbToHtmlItalics($str).clock($t);
    echo "<br />";
    $t = microtime(TRUE);
    echo altbb($str).clock($t);;
    ?>
    i just posted everything i used,
    as you will see, the string method is a lot faster than the regex one and i think a lot simpler also
    i haven't done much testing or anything, just implemented a thought. hope it helps

  • Problem solving using recursive datastructures

    Where from can I download free problems and solutions on java simple data structures and recursive data structures?

    Try http://www.google.com/search?q=java+recursion
    First hit.
    Google is your friend.
    � {�                                                                                                                                                                                                   

  • [SOLVED] Recipie for target all-recursive failed

    Hello Arch Forums! I'm compiling prboom and alephone. Both give me the same error,
    Makefile:285: recipe for target 'install-recursive' failed
    I've done some searching and still haven't found a solution. What is all-recursive, and how can I continue installation?
    Here's the full report:
    make  all-recursive
    make[1]: Entering directory '/home/switch/Downloads/prboom-2.5.0'
    Making all in doc
    make[2]: Entering directory '/home/switch/Downloads/prboom-2.5.0/doc'
    make[2]: Nothing to be done for 'all'.
    make[2]: Leaving directory '/home/switch/Downloads/prboom-2.5.0/doc'
    Making all in data
    make[2]: Entering directory '/home/switch/Downloads/prboom-2.5.0/data'
    make[2]: Nothing to be done for 'all'.
    make[2]: Leaving directory '/home/switch/Downloads/prboom-2.5.0/data'
    Making all in src
    make[2]: Entering directory '/home/switch/Downloads/prboom-2.5.0/src'
    Making all in SDL
    make[3]: Entering directory '/home/switch/Downloads/prboom-2.5.0/src/SDL'
    gcc -DHAVE_CONFIG_H -I. -I../..     -g -O2 -Wall -Wno-unused -Wno-switch -march=native -Wextra -Wno-missing-field-initializers -Winline -Wwrite-strings -Wundef -Wbad-function-cast -Wcast-align -Wcast-qual -Wdeclaration-after-statement -ffast-math -O2 -fomit-frame-pointer -I../../src -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -MT i_sshot.o -MD -MP -MF .deps/i_sshot.Tpo -c -o i_sshot.o i_sshot.c
    i_sshot.c: In function ‘I_ScreenShot’:
    i_sshot.c:234:32: error: ‘png_error_ptr_NULL’ undeclared (first use in this function)
             PNG_LIBPNG_VER_STRING, png_error_ptr_NULL, error_fn, warning_fn);
                                    ^
    i_sshot.c:234:32: note: each undeclared identifier is reported only once for each function it appears in
    i_sshot.c:282:43: error: ‘png_infopp_NULL’ undeclared (first use in this function)
           png_destroy_write_struct(&png_ptr,  png_infopp_NULL);
                                               ^
    Makefile:242: recipe for target 'i_sshot.o' failed
    make[3]: *** [i_sshot.o] Error 1
    make[3]: Leaving directory '/home/switch/Downloads/prboom-2.5.0/src/SDL'
    Makefile:460: recipe for target 'all-recursive' failed
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory '/home/switch/Downloads/prboom-2.5.0/src'
    Makefile:285: recipe for target 'all-recursive' failed
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory '/home/switch/Downloads/prboom-2.5.0'
    Makefile:205: recipe for target 'all' failed
    make: *** [all] Error 2
    Last edited by SwitchDhole (2015-03-04 05:59:45)

    This sounds like a problem that is specific to the package or the code itself. I'm don't use either of those, but I can give you some general recommendations.
    `pacman -Syu` has been known to fix compilation errors when a package depends on a header file that is owned by another package. Unfortunately this works the other way around, too: the packages you're trying to install might depend on an older header file that has been upgraded by pacman. The latter is usually a result of outdated code and is much harder to fix.
    `grep png_error_ptr_NULL -R /usr/include` will show you which header files the identifier appears in (if any). One of them should contain the declaration, so make sure that file is #include'd in i_sshot.c
    For best results, I recommend contacting the package maintainer, posting a comment on the AUR package page, or contacting upstream directly. Those users are likely to be more knowledgeable about this software than the rest of us on the forum.

  • Syntax to delete all .ogg files recursively [solved]

    I'm wondering how to go about recursively deleting all .ogg files from an entire directory structure.
    Would something like this do it?
    find /mount/point -name '*.ogg' -type f -exec rm '{}' \;
    Last edited by graysky (2009-06-07 17:08:18)

    kludge wrote:
    B wrote:
    Why not just
    find /path/ -name *ogg -exec rm {} \;
    damn.  is there an o'reilly book about 'find' yet?  there should be.  i read the man page not too long ago and realized that it's a whole damned file-manager unto itself.
    `man find` and search for '-delete'
    Last edited by Mr.Elendig (2009-06-07 15:36:18)

  • (solved)How to use jpegoptim recursively in subfolders.

    Hello ,
    I want to optimize some images without changing names with many subfolders loaded.
    I am not good at shell script. I found this for jpegtran but package does not work.
    How can I modifiye it for jpegoptim?
    #! /bin/sh
    # Usage 1:
    # optimize-images.sh /images/dir
    # Usage 2:
    # cd /images/dir
    # optimize-images.sh
    EXTENSIONS="jpe?g"
    if [ -z "$1" ]; then
    DIR="`pwd`"
    else
    DIR="$1"
    fi
    # Optimize JPEG images
    find "$DIR" -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}.optimized" "{}"
    # Rename xxx.jpg.optimized -> xxx.jpg
    find "$DIR" -name '*.optimized' -print0 | while read -d $'\0' file; do
    chown $(stat -c "%U:%G" "${file%.optimized}") "$file"
    chmod $(stat -c "%a" "${file%.optimized}") "$file"
    mv -f "$file" "${file%.optimized}";
    done
    ps1: also found this while google in but I dont know where to write it :
    optimize() {
    jpegoptim *.jpg --strip-all
    for i in *
    do
    if test -d $i
    then
    cd $i
    echo $i
    optimize
    cd ..
    fi
    done
    echo
    optimize
    Last edited by ytsejam (2014-03-19 10:20:12)

    ytsejam wrote:It is installed.. I checked it and I can see with pkgfile. I am trying to find out where to write that script now .
    pkgfile shows what's in the sync databases (in the repos), not what is in the local databases (what do you have on your computer).
    ytsejam wrote:
    karol,
    Thank you for efforts , I needed to logout and login .
    optimize() {
    jpegoptim *.jpg --strip-all
    for i in *
    do
    if test -d $i
    then
    cd $i
    echo $i
    optimize
    cd ..
    fi
    done
    echo
    works with jpegoptim. I think the same will occur with jpegtran. I had a $PATH value for ruby , it was ruining my bashrc. I commented it and works now.
    How exactly were you trying to use the script for jpegtran? Did you put it in your ~/.bashrc? You don't have to put your script location in your $PATH to run it, you just need to use the full path then.

  • [Solved] Kde unstable: Folderview recursive mouseover gone?

    In folderview you used to be able to mouseover a folder and browse it's contents (handy, no need to open a file manager)but now it just tells me how many items are in it. Is there an option somewhere I need to tag? Can't believe such a useful feature would have been removed...
    Cheers!
    Last edited by cuervo (2010-07-13 19:00:05)

    It looks like in KDE 4.4 there is no option to disable it. (see http://chakra-project.org/bbs/viewtopic.php?id=1310)Maybe for 4.5 they added the option, but disabled by default. Have you checked the folderview settings? (sorry, I feel stupid asking that question)
    Last edited by drcouzelis (2010-07-12 01:21:40)

  • [SOLVED] bash recursive function

    #!/bin/bash
    IFS=$'\n'
    function low {
    if [ -d "$1" ];
    then
    DIR="$1"
    cd "$DIR"
    fi
    pwd
    for f in `find . -maxdepth 1`; do
    [ -d "$f" -a "$f" != "." ] && low "$f"
    file=$(echo $f | tr A-Z a-z | tr ' ' '_')
    [ -e "$f" ] && [ ! -e "$file" ] && mv "$f" "$file"
    done
    [ "$DIR" ] && cd - > /dev/null
    low .
    unset IFS
    this should walk through all subdirectories and rename the files inside there
    however, it only goes through the first directories it finds.
    i.e. i have:
    /tmp/test1/
    /tmp/test1/sub1/
    /tmp/test2/
    /tmp/test2/sub2/
    and the script does:
    [rob:/tmp/] ./lowandspace
    /tmp/
    /tmp/test2
    /tmp/test2/test2_2
    what am i missing?
    or is bash screwing up?
    Last edited by robmaloy (2009-05-20 09:46:54)

    why would you test -f $file after a find?
    this should work, i use something very similar except mine renames directories too so it's a bit easier to manage.  i overused the double quotes b/c i can't test right now and i want to be sure it handles spaces appropriately
    find ./ -type f | while read file do
    dir="$(dirname "$file")"
    old="$(basename "$file")"
    new="$(echo "$old" | tr A-Z a-z | tr ' ' '_')"
    if [ "$new" != "$old" ]; then
    mv "$dir"/"$old" "$dir"/"$new"
    echo "$old was renamed to $new"
    fi
    done
    Last edited by brisbin33 (2009-05-12 22:17:28)

  • ORA-00604: error occurred at recursive SQL level 1

    Hi,
    i have a view as source (DB2)
    Target table in Oracle with the same structure
    when i view data from the view all the records are listed.
    after mapping the source and target source gets fail while debuging (test data)
    and also while deploying the mapping i get the following error.
    Anyone knows about the following errors
    ACBLODS_MAP
    Create
    Warning
    ORA-06550: line 0, column 0:
    ORA-04052: error occurred when looking up remote object [email protected]@DB2_KAPIL_LOCATION
    ORA-00604: error occurred at recursive SQL level 1
    ORA-28500: connection from ORACLE to a non-Oracle system returned this
    please someone help me to solve this
    thanks in advance
    regards
    raja

    I had a simular problem with progress. If the progress table had to many columns
    OWB was failing. The problem was the ODBC driver used to make a connection to PROGRESS.

  • ORA-00604: error occured at recursive SQL Level 1

    Hi,
    I have installed XE Oracle Database Version 9.0.1.4.0 in VISTA Home Premium and Oracle Developer suite10g version 9.0.4.0.19
    I received the following error message when I try to connect the Database in Form Developer or sqlplusl.
    ORA-00604: error occured at recursive SQL Level 1
    ORA-01009: missing mandatory parameter
    but when i run through XE-database it works fine..
    Any one can you help to solve this problem.
    Thanks in Advance.

    I guess you meant to ask on the XE forum, as this has nothing to do with ADF or JDeveloper.
    John

  • THE ONE WHO SOLVES THIS PROBLEM IS GREAT!

    I'm serious. I am so fed up I am with this problem. Ground rules: you must NOT just give me code. I need to be able to know why my problem is happening, and how to fix it myself. I'm a grad student and am bound by a code of conduct. I don't have any more time to spend investigating this. It could be something simple or complex...I am at a loss.
    Here is the situation: I'm developing this console java application on my Windows PC. When I run it on my pc, it runs in under a minute. However, when I transfer my program to the servers at my school (sun unix workstations) it takes a ridiculous amount of time to run the same program. I am told that 80% of the students in my class have their programs running in less than 5 minutes. Almost all of them didn't have to do any kind of optimizations. They just wrote it, and it worked. My program is averaging 10-15 min, but my prof runs it locally at school, and says it takes 40 min!
    The entire program is posted below. Please forgive me for not commenting so great. They were better at first, but when I started moving things around and changing everything, I threw comments out the window. Still, the existing comments should be helpful in understanding what I'm doing. NOTE: Below the code is the DTD that all the .xml files I'm parsing conforms to. Here are a few links to .xml files that represent part of the dataset. The actual dataset consists of 40 files totaling 30MB.
    http://www.geocities.com/c_t_r_11/items-1.xml
    http://www.geocities.com/c_t_r_11/items-10.xml
    http://www.geocities.com/c_t_r_11/items-20.xml
    the dtd is at:
    http://www.geocities.com/c_t_r_11/itemsdtd.txt
    And here is the code:
    /* Instructions:
    This program processes all files passed on the command line (to parse
    an entire diectory, type "java MyParser myFiles/*.xml" at the shell).
    At the point noted below, an individual XML file has been parsed into a
    DOM Document node. You should fill in code to process the node. Java's
    interface for the Document Object Model (DOM) is in package
    org.w3c.dom. The documentation is available online at
    http://java.sun.com/j2se/1.4/docs/api/index.html
    A tutorial of DOM can be found at:
    http://java.sun.com/webservices/docs/ea2/tutorial/doc/JAXPDOM.html#67581
    Some auxiliary methods have been written for you. You may find them
    useful.
    Modified by:
    Will
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.ErrorHandler;
    class MyParser{
        static DocumentBuilder builder;
        static final String[] typeName = {
            "none",
            "Element",
            "Attr",
            "Text",
            "CDATA",
            "EntityRef",
            "Entity",
            "ProcInstr",
            "Comment",
            "Document",
            "DocType",
            "DocFragment",
            "Notation",
        static final String[] itemTags = {
            "Number_of_Bids",
            "Started",
            "Ends"
        static class MyErrorHandler implements ErrorHandler {
            public void warning(SAXParseException exception)
                    throws SAXException {
                fatalError(exception);
            public void error(SAXParseException exception)
                    throws SAXException {
                fatalError(exception);
            public void fatalError(SAXParseException exception)
                    throws SAXException {
                exception.printStackTrace();
                System.out.println("There should be no errors " +
                        "in the supplied XML files.");
                System.exit(3);
        /* Non-recursive (NR) version of Node.getElementsByTagName(...) */
        static Element[] getElementsByTagNameNR(Element e, String tagName) {
            Vector elements = new Vector();
            Node child = e.getFirstChild();
            while (child != null) {
                if (child instanceof Element && child.getNodeName().equals(tagName))
                    elements.add(child);
                child = child.getNextSibling();
            Element[] result = new Element[elements.size()];
            elements.copyInto(result);
            return result;
        /* Returns the first subelement of e matching the given tagName, or
        * null if one does not exist. */
        static Element getElementByTagNameNR(Element e, String tagName) {
            Node child = e.getFirstChild();
            while (child != null) {
                if (child instanceof Element && child.getNodeName().equals(tagName))
                    return (Element) child;
                child = child.getNextSibling();
            return null;
        /* Returns the text associated with the given element (which must have
        * type #PCDATA) as child, or "" if it contains no text. */
        static String getElementText(Element e) {
            if (e.getChildNodes().getLength() == 1) {
                Text elementText = (Text) e.getFirstChild();
                return elementText.getNodeValue();
            else
                return "";
        /* Returns the text (#PCDATA) associated with the first subelement X
        * of e with the given tagName. If no such X exists or X contains no
        * text, "" is returned. */
        static String getElementTextByTagNameNR(Element e, String tagName) {
            Element elem = getElementByTagNameNR(e, tagName);
            if (elem != null)
                return getElementText(elem);
            else
                return "";
        /* Returns the amount (in XXXXX.xx format) denoted by a money-string
        * like $3,453.23. Returns the input if the input is an empty string. */
        static String strip(String money) {
            if (money.equals(""))
                return money;
            else {
                double am = 0.0;
                NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
                try { am = nf.parse(money).doubleValue(); }
                catch (ParseException e) {
                    System.out.println("This method should work for all " +
                            "money values you find in our data.");
                    System.exit(20);
                nf.setGroupingUsed(false);
                return nf.format(am).substring(1);
        /* Process one items-???.xml file. */
        static void processFile(File xmlFile) {
            Document doc = null;
            try {
                doc = builder.parse(xmlFile);
            catch (IOException e) {
                e.printStackTrace();
                System.exit(3);
            catch (SAXException e) {
                System.out.println("Parsing error on file " + xmlFile);
                System.out.println("  (not supposed to happen with supplied XML files)");
                e.printStackTrace();
                System.exit(3);
            /* At this point 'doc' contains a DOM representation of an 'Items' XML
            * file. Use doc.getDocumentElement() to get the root Element. */
            System.out.println("Successfully parsed - " + xmlFile);
            /*Open the output files for each relation****************************/
            PrintWriter itemsFile = null, usersFile = null,
                    bidsFile = null, categoriesFile = null;
            /*Open files for writing each of the txt files******************/
            try{
                itemsFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Items.dat", true)), true);
                usersFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Users.dat", true)), true);
                bidsFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Bids.dat", true)), true);
                categoriesFile = new PrintWriter(new BufferedOutputStream(new FileOutputStream("Categories.dat", true)), true);
            }catch(FileNotFoundException e){
                System.out.println("Error trying to open an output file: " + e.getMessage());
                System.exit(0);
            /*Parse content for each relation in turn********************/
            //Write to the Items.txt file
            NodeList itemNodes = doc.getDocumentElement().getElementsByTagName("Item");
            final String colSep = "|#|";
            String itemID = null;
            Element[] categories = null;
            NodeList bids = null;
            NodeList eBid = null;
            NodeList bidders = null;
            Element tempElement = null;
            Element itemElement = null;
            Element thisBid = null;
            String description = new String();
            for(int i=0; i<itemNodes.getLength(); i++){
                //Get the item Element for this iteration
                itemElement = (Element)itemNodes.item(i);
                /*Write out ItemID**************************************/
                itemID = itemElement.getAttribute("ItemID");
                itemsFile.print(itemID);
                itemsFile.print(colSep);
                /*Write out Name****************************************/
                itemsFile.print(getElementTextByTagNameNR(itemElement, "Name"));
                itemsFile.print(colSep);
                /*Write out the Currently element***********************/
                itemsFile.print(strip(getElementTextByTagNameNR(itemElement, "Currently")));
                itemsFile.print(colSep);
                /*Write out the Buy_Price element, if it exists*********/
                Element checkNode = null;
                if( (checkNode = getElementByTagNameNR(itemElement, "Buy_Price")) != null){
                    itemsFile.print(strip(checkNode.getFirstChild().getNodeValue()));
                itemsFile.print(colSep);
                /*Add the First_Bid element*****************************/
                itemsFile.print(strip(getElementTextByTagNameNR(itemElement, "First_Bid")));
                itemsFile.print(colSep);
                /*Now iterate over the next three elements, adding them in turn*/
                for(int j=0; j<itemTags.length;j++){
                    itemsFile.print(getElementTextByTagNameNR(itemElement, itemTags[j]));
                    itemsFile.print(colSep);
                /*Add the SellerID**************************************/
                itemsFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("UserID")
                        + colSep);
                /*Finally, add the description.  Truncate, if necessary*/
                description = getElementTextByTagNameNR(itemElement, "Description");
                itemsFile.print(description.substring(0, Math.min(4000, description.length())));
                itemsFile.print(colSep);
                itemsFile.println();
                /*Locate all of the Categories******************************/
                categories = getElementsByTagNameNR(itemElement, "Category");
                /*For every category in this item, write a ItemID-Category pair*/
                for(int j=0; j<categories.length; j++){
                    categoriesFile.print(itemID + colSep);
                    categoriesFile.print(categories[j].getFirstChild().getNodeValue());
                    categoriesFile.println(colSep);
                if( (bids = itemElement.getElementsByTagName("Bid")) != null){
                    /*Go through the bids, writing the info***********/
                    for(int j=0; j<bids.getLength(); j++){
                        thisBid = (Element)bids.item(j);
                        bidsFile.print(getElementByTagNameNR(thisBid, "Bidder").getAttribute("UserID"));
                        bidsFile.print(colSep);
                        bidsFile.print(itemID);
                        bidsFile.print(colSep);
                        bidsFile.print(getElementTextByTagNameNR(thisBid, "Time"));
                        bidsFile.print(colSep);
                        bidsFile.print(strip(getElementTextByTagNameNR(thisBid, "Amount")));
                        bidsFile.println(colSep);
                /*write out userid and rating from any and all bidder nodes*/
                if( (bidders = itemElement.getElementsByTagName("Bidder")) != null){
                    for(int j=0; j<bidders.getLength(); j++){
                        usersFile.print(bidders.item(j).getAttributes().getNamedItem("UserID").getNodeValue());
                        usersFile.print(colSep);
                        usersFile.print(bidders.item(j).getAttributes().getNamedItem("Rating").getNodeValue());
                        usersFile.print(colSep);
                        //If there's a location node, write it
                        if( getElementByTagNameNR((Element)bidders.item(j), "Location") != null){
                            usersFile.print(getElementTextByTagNameNR((Element)bidders.item(j), "Location"));
                        usersFile.print(colSep);
                        //If there's a country node, write it
                        if( getElementByTagNameNR((Element)bidders.item(j), "Country") != null){
                            usersFile.print(getElementTextByTagNameNR((Element)bidders.item(j), "Country"));
                        usersFile.println(colSep);
                /*Now write out the Seller information*******************/
                usersFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("UserID"));
                usersFile.print(colSep);
                usersFile.print(getElementByTagNameNR(itemElement, "Seller").getAttribute("Rating"));
                usersFile.print(colSep);
                usersFile.print(getElementTextByTagNameNR(itemElement, "Location"));
                usersFile.print(colSep);
                usersFile.print(getElementTextByTagNameNR(itemElement, "Country"));
                usersFile.println(colSep);
            itemsFile.close();
            usersFile.close();
            bidsFile.close();
            categoriesFile.close();
        public static void main (String[] args) {
            if (args.length == 0) {
                System.out.println("Usage: java MyParser [file] [file] ...");
                System.exit(1);
    /* Initialize parser. */
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setValidating(true);
                factory.setIgnoringElementContentWhitespace(true);
                builder = factory.newDocumentBuilder();
                builder.setErrorHandler(new MyErrorHandler());
            catch (FactoryConfigurationError e) {
                System.out.println("unable to get a document builder factory");
                System.exit(2);
            catch (ParserConfigurationException e) {
                System.out.println("parser was unable to be configured");
                System.exit(2);
    /* Process all files listed on command line. */
            for (int i = 0; i < args.length; i++) {
                File currentFile = new File(args);
    processFile(currentFile);
    REMEMBER: Please do not just post the correct code. This will violate my code of conduct. I need tutoring--consultation.

    If I was trying to get someone else to do my work,
    I wouldn't be posting this saying what I have said
    would I? I'm not unwilling to do the work myself.From what was stated in your OP, it seemed that you
    were.I'm sorry if it seemed that way. I don't want something for nothing. I've spent MANY hours, which I don't have, trying to work this out. I have hit a point where I don't think my expertise is going to solve the problem. That's why I've turned to some experts who might say something along the lines of, "Hey, I know what that is...you're compiling against... and on the Unix box, it's compiling against..." I was NOT looking for something like, "See the code below that fixes your problem."
    The only problem is that I don't have direct access
    to the sun unix machines I'm running the app on,
    so I can't run a profiler on it. Ah, okay. So the only knowledge you have of how it
    performs on those machines is from your instructor
    running it and then telling you how long it took?No. I can SSH into the servers and run the program from a command line. But I wouldn't be able to install any profiler programs.
    You could ask your prof to run it with -Xprof or
    -Xhprof or whatever. Or you could put in a bunch of
    timing statements to get a rough idea of which parts
    are making it take that extra 39 minute or whatever.is -Xprof a java command line option? If so, I will look into doing that. Maybe it's available on the machines at school. Thanks for that input.

Maybe you are looking for

  • Consequences of using unconstrained query variables?

    I'm trying to determine what the consequences are (if any) of using unconstrained query variables vs using variables with a contains clause in order to navigate through collection fields. In the Java Data Objects book the example given for collection

  • EDI ANSI X12 and relavent IDOC types and messages...

    Hi ,     Is there any place where we can get the relevant Idoc types and messages for EDI Transacitons below: 210 -Motor Carrier Freight Details and Invoice 240 -Motor Carrier Package Status 753 -Request for Routing Instructions 754 -Routing Instruct

  • Link to Standard repository(s) MDM7.1

    Hi All, Could you please let me know the direct link to download the MDM 7.1 standard repository(s). thanks, Alexander.

  • Not full month depreciation

    Dear SAP Experts, We have a need to calculate the fixed assets depreciation - not for the full month, but just the last 3 weeks of it. For example,  we post the APC as of 01/07/11. We need to depreciate our fixed assets from 01/08/11 to 01/31/11 only

  • System Utilities Check failed while rapid installation

    Hi All, Following error is encountered while installing Oracle Applications 11.5.10 System Utilities Check command : cmd.exe /c C:\Stage\Stage11i\startCD\Disk1\rapidwiz\bin\adchkutl.cmd C:\Program Files\MKS Toolkit C:\VC C:\Stage\Stage11i\startCD\Dis