Editing question, preferably with "do shell script"

I would like to edit an expression
from: blah blah /Paragraphs/one two three
to: blah blah /Paragraphs/one-two-three
where "/Paragraphs/" is always present
but "one" might be anything
Using sed with regexp seems like a way to go, but I don't know how to designate "one," which will vary. Viz.:
set T to "blah blah /Paragraphs/one two three"
set T1 to do shell script "echo " & quoted form of T & " | sed 's/\\/Paragraphs\\/{anything}/\\/Paragraphs\\/{anything}(change all subsequent spaces to "-")/g'"

Hi,
Can't believe I did it with sed! My test.txt file looks like this:
blah blah #one here's some text
blah blah #two more text
blah blah #three and even more text
#four number begins this line
Here's the sed part:
sed 's/#/\
#/' < test.txt | sed '/#/ s/ /-/g' | sed '
N
s/\n#/#/
Here I used "#" instead of "/Paragraphs/". Now, you translate this into a do shell script. If you need help with that, then write back. I now understand the N command for working with multiple line processing. Here's the tutorial I used:
http://www.grymoire.com/Unix/Sed.html
Edited: and here's the output
blah blah #one-here's-some-text
blah blah #two-more-text
blah blah #three-and-even-more-text
#four-number-begins-this-line
gl,

Similar Messages

  • Schedule workbook using with Unix shell script

    Hi,
    Can we schedule workbook using with Unix shell script?
    Thanks,
    Jay

    I can't imagine how.
    1. You can schedule Disco workbooks via Disco itself.
    2. You can schedule Disco workbooks to run and output in different file formats automatically via batch scheduler in Windows running Disco Desktop directly (or can user VBasic).
    3. You can schedule Disco workbooks to run and output in different file formats automatically via a Java program running the Java Command Line interface.
    Moving forward, Oracle has announced that with a further interfacing of Disco with XML Publisher, you'll be able to use Oracle Apps concurrent manager and scheduling. But that's coming supposedly at the end of this year.
    And I think that's about it.
    Russ

  • Trying to run program off network location using GPO with Power shell script.

    Hello All,
    Not much of a script writer. I am giving it a shot.  My issue is that I need to run a application update across our network and I am trying to do it with as little hands on as possible. So I was planning to push a GPO with a power shell script in it
    to run the program with elevated privileges. 
    Little background:
    We are running on a domain and end users do not have admin rights.
    The application is stored on a share on our network that is open to all domain users.
    The installer user name and password is a temp one and will only be valid for the 30 min window when everyone logs in at the beginning of the day.
    So this is what I have so far.
    $username = "USER"
    $password = "PASSWORD"
    $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
    Start-Process PSQLv11Patch_Client_x86.msp -Credential ($credentials) -WorkingDirectory \\Server\Folder\Folder1\Folder2\filder3\PSQLv11sp3_x32\
    But for some reason I keep getting :
    Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
    At line:10 char:1
    + Start-Process PSQLv11Patch_Client_x86.msp -Credential ($credentials) -WorkingDir ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
    Any help you could give would be great.
    Thanks,
    jdfmonkey

    Hi jdfmonkey,
    Has anyone provided an answer to your original question?  I am trying to use Start-Process to launch a process using another logged in user's credentials, and am not able to get it working:
    $cred=Get-Credential
    start-process Process.exe-WorkingDirectoryC:\Scripts-Credential$cred
    I get the same error that you mentioned:
    start-process : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\Scripts\Process.ps1:2 char:1
    + start-process Process.exe -WorkingDirectory C:\Scripts -Credential ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
    When I leave off the credentials:
    start-processProcess.exe-WorkingDirectoryC:\Scripts
    It works correctly.  Does anyone have a solution to make this work correctly?
    Please ask your own question.  You issue is nothing like the current thread.  You clearly are using a user account that has no access to the folder.  It is a permissions issue.  It is not a scripting issue.
    If you need further help please start your own question.
    ¯\_(ツ)_/¯

  • Having problems with a shell script

    I'm trying to write a shell script that will echo back the command, and ask for confirmation before proceeding with the command.
    Here is what I have so far:
    Josh:~ josh$ cat ~/Desktop/safe
    #!/bin/sh
    echo "You have typed: "$1 $2 $3 $4"."
    read -p "Are you sure you want to continue? (y/n)" a
    if [ "$a" = "y" ]; then
    $1 $2 $3 $4
    elif [ "a" = "n" ]; then
    exit
    elif [ "a" != "y" ] [ "a" != "n" ];then
    echo "Type y or n."
    fi
    When I run it, and type n, (y works fine) I get a syntax error: ./safe: line 10: [: too many arguments
    Could you please help me fix it?
    Thanks!
    EDIT: If I change the last "elif" statement to a simple "else", it automatically does that statement anyway when the user types "n".
    Is there any better way to end the script when the user types "n"?
    Message was edited by: joshz
    Message was edited by: joshz
    Message was edited by: joshz
    Message was edited by: joshz

    joshz wrote:
    A few q's.
    1. you have "n=$#", but never use n. What is that for?
    Er... because I originally did it differently and then forgot to go back and delete this line!
    2. Why do you set list to a blank string? Just to initialize it?
    Yes. Habit. Sometimes it is an error to use an unassigned variable. It would not matter in this case because echo will not complain, but it still appeals to my sense of logic/tidiness. It also means that if I later change something in my script so that an unassigned variable will cause an error, I won't be stymied by a failure I can't explain. (Not really an issue in a script this short but might well be in a longer script.)
    3. "sed 's+, $+ and all enclosed files/folders+'" What does it do? What is s supposed to do? I know that s treats a string as a single line, but what's the purpose of that (and the +)? $+ would stand for the end of a line, but repeated one or more times. Why have the +'s?
    In this case, s is for substitute. The + is an arbitrary delimeter. A forward slash is standard, but if I use + I don't have to escape the slash in the phrase "and... files/folders". The whole thing says:
    Take the piped output from echo and find every occurrence of the pattern consisting of a comma followed by a space followed by an end of line (on every line of the piped input, but there's only one here). Substitute the first occurrence you find (on every line of the piped input, but there's only one here) with a space followed by "and... files/folders".
    Also, I ideally want the "and all enclosed files/folders" to appear only if there is a recursive option turned on, not all the time. (I guess it would be good enough to have it turn on if there's an r OR R option, because it would be too hard to program it in based on each command).
    To do that properly, you need to do things differently so that you can distinguish between arguments to the command and occurrences of strings in the names of files and folders. For example, you might have a folder named "My Folder-Revised". There are ways of doing this but they are not as simple as the sort of framework you're using here.
    If you are concerned about accidentally deleting files, have you considered using an alias called "rm" for "rm -i". That way, you do not have to remember to use "safe" either. Unfortunately, that won't work for "sudo rm". On the other hand, "sudo safe" won't necessarily work either. Where are you planning to install your script?
    - cfr

  • Issue with calling Shell Script using DBMS_SCHEDULER

    Hi All,
    I am executing a shell script using DBMS_SCHEDULER from APEX web page. Execution part is working fine without any issues.
    In my shell script file (abc.sh) I have few oracle sql procedure calls which connects back to same database and that SQL call is not executing some reason, it not giving any errors.
    Inside my shell script code looks like this.
    sqlplus -silent $USER/$PASSCODE@$SCONNECT > /dev/null <<END
    set pagesize 0 feedback off verify off heading off serveroutput on
    echo off linesize 1000
    WHENEVER SQLERROR EXIT 9
    BEGIN     
    dbms_output.enable(1000000);
    do_enable_cons();
    dbms_output.disable;
    END;
    spool off;
    exit;
    END
    When I run this shell script file from backend it works fine now issues.
    Is there any restrictions in executing sql code using DBMS_SCHEDULER? Any ones help is much appreciated.
    -Regards

    james. wrote:
    Thanks you sb and Sybrand . It is problem with environment variables. After running .bash_profile in the beginning of the shell script, it is working fine.
    One issue is when I check the process it is showing two entries with two different process id's.
    The command I used
    ps -ef | grep <my script> is COPY & PASTE broken for you?
    any reason why you did not show us EXACTLY was produced by OS command above?
    >
    Is it something wrong with my code or is it normal? Is it really executing two times ?
    -Regards
    bcm@bcm-laptop:~$ sqlplus user1/user1
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 20 15:14:15 2012
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    15:14:15 SQL> !ps -ef | grep sqlplus
    bcm      24577  1903  1 15:14 pts/0    00:00:00 sqlplus           
    bcm      24579 24577  0 15:14 pts/0    00:00:00 /bin/bash -c ps -ef | grep sqlplus
    bcm      24581 24579  0 15:14 pts/0    00:00:00 grep sqlplus
    15:14:23 SQL> how many different copies of "sqlplus" running on my laptop based upon actual output above?

  • Problem with executing shell script on linux through java code.

    i am facing problem to kill jboss process on linux that is my application requirement. for that i created one shell script that will get all the process for jboss instance and kill them when i am running that script from command prompt on linux its working perfectly.
    The command i am using ---
    /opt/RW9/jboss/v4.0.5.GA/bin/restartjboss.sh.
    but when i am running through java code its not working.
    the java code i am using is:-
    pp = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "/opt/RW9/jboss/v4.0.5.GA/bin/restartjboss.sh"});
    could anyone tell me what is the problem ?
    Edited by: akm198110 on Sep 2, 2008 9:24 AM

    I got the problem after long struggle ,after doing proper path i am able to execute the shell script..

  • Trying to close an app with a shell script which was launched by same app.

    This may be simple, but is confusing me. I have an app that executes a shell script at launch. The script is designed to check for the existence of files and if not found, I want to display a message and close the application. The problem seems to be that I can't close the app with the script, since the script was called by the app and the shell is tied up. Does that make sense? I can't close the app because the script/shell is still active. Any ideas?

    Just have the script output some value for the app to read and then quit. Once the app reads the value, it will wait for the script to quit (shouldn't take long, especially if the script isn't running anymore) and then, if the value is a flag to quit, quit.

  • Refreshing a status bar with a shell script

    Hello,
    I use the lemonbar to display some informations about my system. The lemonbar
    use a shell script to display informations. Sometimes I want to refresh my status bar.
    To be brief: is it possible to refresh the status bar without checking for example every 2 seconds with
    a "sleep 2" command ?
    Let's take an example: with my window manager I switch
    from desktop 1 to desktop 2. At the moment I use a sleep command and I refresh the information
    every 2 seconds. Is there a way my shell script get notified about the switch from desktop 1 to desktop 2 and can refresh
    the information in my status bar ? So it would be not necessary to execute a sleep command every two seconds.
    Until now I found nothing. An idea is to react to a keyboard shortcut (the switch from desktop 1 to desktop 2), but
    I don't know if it's possible.  Perhaps something with a signal ? I also know some X events are generated by creating or closing windows
    for example. I don't know if reacting to X events would be another possibility.
    Thank you!

    kokoko3k wrote:Eg: if a WM writes the current desktop in a file, then you can just watch that file via inotify and do an event driven action.
    I will keep it in mind. I have to check, but it's possible I can use that solution.
    kokoko3k wrote:As a side note: how do you switch "desktops" without a WM? Was it just an example?
    Yes, it was an example. If I change in the future I could use the solution for the chosen wm.
    But at the moment I can create groups. Each groups get a number and I can raise or hide all applications
    in that group. So it's the same problem.

  • Assistance with Automator Shell Scripting

    Is there a way to take the Ask for text, set the returned value as a variable and use that variable later on in a Shell Script action?
    Thanks in Advance

    This is showing how you would access your variables. $@ will contain all the command line variables and the for do loop intinerates over each one one at a time.
    So you would replace this with your script of course but thats how you would access the arguments.

  • Help with broken shell script

    Hi,
    We had the shell script below created for our school last year to keep the students from jumping off of our wireless network so they had to go through our content filters. We put the script on all of the student laptops (MacBooks and MacBook pros) so it ran as a process in the background. It worked beautifully for the  whole year.
    Now we are in the process of upgrading our laptops from Snow Leopard to Lion and we've discovered that the script no longer works in Lion. I am guessing it is something simple but I don't see it. Does anyone know what about the OS changed that would cause this script to stop working?
    Thanks
    Tim
    #!/bin/sh
    currentSSID=`networksetup -getairportnetwork Airport | awk {'print $4'}`
    if [ "$currentSSID" = "optimumwifi" ] ; then
            echo "Disassociating.."
            /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
            networksetup -setairportnetwork Airport "Student" "only4study!"
    fi
    if [ "$currentSSID" = "timewarnercablewifi" ] ; then
            echo "Disassociating.."
            /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
            networksetup -setairportnetwork Airport "Student" "only4study!"
    fi
    if [ "$currentSSID" = "xfinitywifi" ] ; then
            echo "Disassociating.."
            /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/ai rport --disassociate
            networksetup -setairportnetwork Airport "Student" "only4study!"
    fi

    Brilliant, that worked perfectly! Thanks for the your help Linc.
    Coincidentally, I found a posting on the website stackexchange.com that helped explain why it stopped working in the first placed and why "Airport" alone used to work in Snow Leopard.
    Note what it says at the bottom:
    "the port name is Wi-Fi on 10.7 and AirPort on 10.6. The device name can be at least en0,en1, or en2 depending on your setup."
    http://apple.stackexchange.com/questions/36891/bash-script-to-toggle-wifi-in-lio n

  • Trouble with: "do shell script" password

    Here's the code I'm trying to use to unlock my login.keychain via Applescript:
    do shell script "security unlock-keychain login.keychain" password "mypasswordgoeshere"
    I'm getting the following error message in AppleScript Editor:
    error "password to unlock login.keychain:
    security: SecKeychainUnlock login.keychain: The user name or passphrase you entered is not correct." number 51
    Any suggestions on how to get this working?

    That function uses the password differently. Run the following:
    do shell script "security unlock-keychain -p password login.keychain"
    (52720)

  • Problems with executing shell script within oracle procedure

    I have procedure that's owned by Semantic user. This procedure calls job scheduler (owned by USER1) which in turn executes a shell script load_semantic.sh (owned by USER1).
    Now, there is a shell script(checkCount.sh)inside of this one (owned by this USER1) that has following contents:
    checkCount.sh
    #!/bin/bash
    MODEL=$1
    sqlplus -S user/pass << EOF
    whenever sqlerror exit 1;
    set echo on
    set verify off
    MERGE INTO SEMANTIC.COUNT_STATISTICS s
    USING (SELECT '$MODEL' AS MODEL, 0 AS NEW_COUNT, SYSDATE AS NEW_DATE, 0 AS OLD_COUNT, SYSDATE AS OLD_DATE FROM dual) t
    on (s.MODEL = t.MODEL)
    when not matched then
    INSERT (s.MODEL, s.NEW_COUNT, s.NEW_DATE, s.OLD_COUNT, s.OLD_DATE)
    VALUES (t.MODEL, t.NEW_COUNT, t.NEW_DATE, t.OLD_COUNT, t.OLD_DATE);
    COMMIT;
    UPDATE SEMANTIC.COUNT_STATISTICS SET  MODEL = '$MODEL', NEW_COUNT = (SELECT COUNT(*) FROM TABLE(SEM_MATCH('{?s ?p ?o}',SEM_Models('$MODEL'),NULL,SEM_ALIASES(SEM_ALIAS('','http://VISION/DataSource/SEMANTIC#')),NULL)) ),NEW_DATE  = SYSDATE,
    OLD_COUNT = NEW_COUNT, OLD_DATE  = NEW_DATE WHERE MODEL = '$MODEL' AND NEW_DATE = (select max(NEW_DATE) from SEMANTIC.COUNT_STATISTICS where MODEL = '$MODEL');
    COMMIT;
    exit;
    EOF
    So when I execute SEMANTIC.PROCEDURE:
    SEMANTIC.PROCEDURE => USER1.JOBSCHEDULER =>USER1.load_semantic.sh =>USER1.checkCount.sh
    It never populates the table SEMANTIC.COUNT_STATISTICS.
    I tried giving all of the permissions but I am probably missing something...
    Maybe fresh eyes can see something that I can't.

    I can't believe I am going to say this but the reason it was not working was because I removed oracle environment path from my script by mistake.
    . /etc/profile.d/oracle.sh
    Ugh...
    Now it is working perfectly.
    Btw, sqlplus does know about shell environment variables.
    THANK YOU GUYS!!! YOU ARE THE BEST!!!!!!!!!!!!!!!!!!
    I ONLY HAVE YOU TO TALK TO WHEN I AM STUCK ON A PROBLEM.

  • [solved] Question about Quotes in Shell-Script

    I searched for a way to rename my music album folders strictly to the format '<artist> - <album> (<year>)'. I couldn't archieve this with KRename and didn't find an alternative way so i tried to script it. It's really bad i know, but it works for me. I usually use it to rename a bunch of folders in a zsh for loop 'for i in *; dirn $i | tee -a rename.sh'
    The Problem now is some albums have " Quotes in it so the Script fails (Line 56).
    http://pastebin.com/rePQev61
    Maybe someone here can enlighten me how to get folders like these right in the script:
    David Bowie - "Heroes" (1977)
    Portugal. The Man - Waiter: "You Vultures!" (2006)
    The Crickets - The "Chirping" Crickets (2004)
    The Long Blondes - "Couples" (2008)
    Last edited by modulation (2010-12-11 09:05:49)

    I'm not sure i get this. $newdir is the corrected name for the album folder. I already strip invalid chars in line 47 (sed -e 's/[|\<>%?^:*\/]/_/g'). But i've trouble with the output of the rename command.
    I'd like it to output something like:
    mv 'crinckets_the_chiping' 'The Crickets - The "Chirping" Crickets (2004)'
    so that the newdir really contains the "-Quotes.

  • Help with a shell script for schroot

    Since I replaced dchroot with schroot I have a problem.
    In /usr/bin I have a script run32.sh to run 32 bit applications, and symbolic links like acroread32 pointing to run32.sh, firefox32 pointing to run32.sh etc.
    Here is the run32.sh I had before
    #!/bin/bash
    cmd=`basename $0 | sed -n s/32//p`
    for (( i=1; $i<=$#; i=$i+1 )); do
    esc[$i]=$(sed -e 's#\([^[:alnum:]]\)#\\\1#g' <<<${!i})
    done
    exec schroot -p "$cmd" "${esc[@]}"
    The for loop is a trick I stole from the web for escaping some characters.
    But this is not working anymore with schroot.
    So I modified run32.sh like this:
    #!/bin/bash
    cmd=`basename $0 | sed -n s/32//p`
    ct=0
    arg=\"
    for i in "$@"
    do
    ct=$(($ct+1))
    if [ $ct -eq 1 ]
    then
    arg="$arg$i"
    else
    arg="$arg $i"
    fi
    done
    arg=$arg\"
    echo exec schroot -p $cmd $arg
    exec schroot -p $cmd $arg
    Notice that at the end I echo the exec command and then I execute it.
    It works fine for simple arguments, like
    acroread32 foo.pdf
    but not for composite arguments like
    acroread32 foo boo.pdf
    or
    acroread32 foo\ boo.pdf
    (this last one is when I use the tab key to complete the name of the file).
    The thing that I really don't understand is that, typing
    acroread32 foo boo.pdf
    the echoed command is
    exec schroot -p acroread "foo boo.pdf"
    and I get an error
    I: [Arch32-8398824e-10d9-4adf-a299-10c09116e262 chroot] Running command: "acroread foo boo.pdf"
    but then, if i type directly to the command line
    exec schroot -p acroread "foo boo.pdf"
    it opens the file!
    Has somebody a solution to deal both with files like "foo.pdf" and "foo boo.pdf"?

    jacko wrote:Is there any reason your choosing to use acroread over some other form of pdf viewer via a chroot?
    Usually I use kpdf but for some particular features acroread is better. But it's not the point, acroread is just an example. You can do another example with firefox 32 bit, that I use for flash and jre, and mplayer 32 bit, that I use for some win32 codecs.

  • Midi editing questions, start with 3 question first :)

    1- I want to edit note length to the exact figure. Why always go more then i want(smart selected)? Is there further setting for snap? Just stop on that measure. Smart selected goes like next bar until 2.0.0.95.. Why 95?
    How to set auto quantize recording so i no need to edit note lengths.
    2- I record 5 regions on same track (usually with drum) After number 5, i want to see the first take. I still can't go into. I need to merge everything.
    3- For example drum track and there is kick need to lower the volume. I click on the piano roll, will select all kicks. I want to enter the value that i want, so all those selected notes will be affect
    Is it ok my English? Can you understand clearly?

    Zorton wrote:
    1- I want to edit note length to the exact figure. Why always go more then i want(smart selected)? Is there further setting for snap? Just stop on that measure. Smart selected goes like next bar until 2.0.0.95.. Why 95?
    Search for the "Snap" Menu it is located up to the grid arrange window in the rigth side... is set by default as "Smart" it is good for al most uses but you cab choose different mode in the snap menu
    How to set auto quantize recording so i no need to edit note lengths.
    Quantize is located in the "inspector" strip at the first corner inside instrument
    to select auto quantize (this is not the correct therm in Logic because the midi events can be easky de-quantize...
    anyway, just selct your favourite Quantize groove when any Region must be selected...
    if a MIDI region is selected the quantize value that you choose will works only in the selected region.
    2- I record 5 regions on same track (usually with drum) After number 5, i want to see the first take. I still can't go into. I need to merge everything.
    I don't use take function... during MIDI recording.. i cannot help about that
    (I'm a old School Logic user I hate take-comp feature)
    3- For example drum track and there is kick need to lower the volume. I click on the piano roll, will select all kicks. I want to enter the value that i want, so all those selected notes will be affect
    you must select only the note that you want edit...
    if you selct more than one... obviuosly, all those selected notes will be affect
    for deselect click on empty grid windows... all notes will be deselect and you will be able to select the desidered one.
    Is it ok my English? Can you understand clearly?
    don't worry about that..., I'm from Italy... and I don't know anything about English.. I just try to be clear (sorry for my mistakes)
    you are welcome.
    G

Maybe you are looking for