Do shell script with SED

I've used this a lot and have never observed this behavior; if it's normal I must really not have been paying attention.
If I have a file (/Q.txt) which contains
cnow
cis the time
cto call
and do this: do shell script "sed 's/c//' < /Q.txt"
the result is
now
is the time
to call
which is what I would expect.
HOWEVER, if use this approach:
set T to "cnow
cis the time
cto call"
do shell script "echo " & quoted form of T & "| sed 's/c//'"
the result is
now
cis the time
cto call
(I can't use the global form, as that will remove other instances of "c")
The only way I can think this will happen is if "echo" removes the returns from T; but looking at the output of echo by itself the result looks okay. And the paragraph count of that result is the same as for T.
What dumb thing am I doing now?

Your issue is with the newlines (or other invisible characters) that are getting used. When I copied your example script, it worked as expected (the first match is replaced on each line). I don't know why the Script Editor would use different newline characters, but you can see from the following example how SED works with various ones:
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
-- use a FF as the newline
set T to "cnowc" & (ASCII character 10) & "cis the timec" & (ASCII character 10) & "cto callc"
do shell script "echo " & quoted form of T & "| sed 's/c//'"
--> correct
-- use a CR as the newline (same as 'return')
set T to "cnowc" & (ASCII character 13) & "cis the timec" & (ASCII character 13) & "cto callc"
do shell script "echo " & quoted form of T & "| sed 's/c//'"
--> same as your result
-- the 'backslash-n' is a newline character that gets converted at compile time
set T to "cnowc\ncis the timec\ncto callc"
do shell script "echo " & quoted form of T & "| sed 's/c//'"
--> correct
-- replace all
set T to "cnowc\ncis the timec\ncto callc"
do shell script "echo " & quoted form of T & "| sed 's/c//g'"
</pre>
Since I can't see what you are using to generate the newlines (but they look the same), I am guessing that the wrong newline is getting placed in there. Copying from various sources may wind up with the different newline characters.
Message was edited by: red_menace

Similar Messages

  • How do you pass shell scripts with cocoa?

    How do you pass shell scripts with cocoa?

    You asked for more detail -- I don't know if this is what you were referring to or not, but here's a little more detail on how to use the system() function if that's what you wanted to know.
    As etresoft mentioned, the system() function can be useful for the kind of thing you are talking about. You will need to write the following statement at the top of your code if you want to use it:
    #include <stdlib.h>
    To use the system() function, simply put the command as you would write it in the Terminal between double quotes between the parenthesis. For example, something as simple as:
    system("ls");
    I don't what the practical use of the above statement would be, but it will run, and that's the general format for the system() function. So just put between the quotes whatever command you want to send.
    Hope there was something helpful here.

  • Executing a shell script with DBMS_SCHEDULER

    Hi,
    when I execute a shell script with DBMS_SCHEDULER this doesn't works correctly
    BEGIN
    DBMS_SCHEDULER.create_job
    job_name => 'job_AR',
    job_type => 'EXECUTABLE',
    job_action => '/home/crm/crmdw/AR/start_execution.sh',
    enabled => TRUE,
    start_date => systimestamp,
    repeat_interval => 'FREQ=MINUTELY;INTERVAL=15',
    comments => 'Test Job AR'
    END;Inside the shell script there is a code who call a Hierarchy of process,
    if I executed it manually or with a cron, it works perfectly
    but when I execute it with the job that I've described before it's executes
    all process at same time and it doesn't work.
    What can I do to fix the issue,
    any Ideas?
    Thanks in advanced...

    #!/usr/bin/ksh
    #test_dbms_scheduler.ksh
    echo $1
    echo "I am in Unix"
    exit 0
    chmod 755 test_dbms_scheduler.ksh
    Create or replace procedure test_dbms_scheduler
    as
    v_text varchar2(255) := 'Parameter passed from Oracle to Unix';
    Begin
    dbms_output.put_line("I am in Procedure");
    dbms_scheduler.create_job
    (job_name=>'test_dbms_scheduler',
    job_action=>'/usr/bin/test_dbms_scheduler.ksh',
    number_of_arguments=>1,
    job_type=>'executable',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=SECONDLY; INTERVAL=1',
    enabled=>false,
    auto_drop => TRUE,
    comments=> 'Run shell-script test_dbms_scheduler.ksh');
    dbms_scheduler.set_job_argument_value(job_name =>'test_dbms_scheduler', argument_position => 1, argument_value => v_text);
    dbms_scheduler.enable('test_dbms_scheduler');
    dbms_output.put_line("I am back in Procedure");
    Exception
    when others then
    dbms_output.put_line(sqlcode||sqlerrm);
    end;
    set serveroutput on
    exec test_dbms_scheduler;

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • Sqlplus in Shell Script with startup pfile

    I have the following entry in my Korn shell script:
    ${ORACLE_HOME}/bin/sqlplus -s /nolog << EOSQL >> ${PR_LOG}
    connect / as sysdba
    whenever sqlerror exit sql.sqlcode;
    startup pfile "/u01/app/oracle/admin/${ORA_SID}/pfile/spfile${ORA_SID}.ora";
    EOSQL
    When I execute the script I get the following errors:
    LRM-00123: invalid character 0 found in the input file
    ORA-01078: failure in processing system parameters
    I've isolated the problem to the 4th line. When I change it to simply "startup", everything works. I did try changing the quotes to ` and ', but those didn't work. I even explicitly listed the ORA_SID, and I'm still getting the same error messages.
    Any ideas how I can resolve my problem with the 4th line? All help is appreciated.

    and yes I want to start the database with the spfile.
    If I just use "startup", everything is fine; and I can start the database with the spfile, because I have a symbolic link under $ORACLE_HOME/dbs to point to my actual spfile location - /u01/app/oracle/admin/salsa/pfile/So... what's the problem ? Just use "startup", if I'm not wrong you'd use the same spfile.
    To use that syntax you should create a file with a line like this
    spfile=<path of spfile>
    and start as
    startup pfile='<path of that file>'

  • Problem with the run_job,shell script with sqlldr

    Hi Gurus,
    I Created a job which calls the shell script and i understood from the other posting this job is going to execute with nobody,
    I had done the below testing
    Test 1) Shell script calls the SQL file, this SQL file executes the procedure.
    Test 2) Shell script calls the sqlldr command.
    When i execute the Test cases with , dbms_scheduler Run_job procedure, Test1 is success but Test2 was failed
    When i execute the Test cases with, logging into box with owner of the shell & both test cases are successful.
    Parent folder & Shell files are given with 777 permissions. & the Oracle db is version 10.2.0.1.0.
    Error:
    STANDARD_ERROR="SQL*Loader-522: lfiopn failed for file (*.log)"
    Please provide me your inputs its bit urgent Thanks a lot for your help.
    Edited by: 926769 on May 23, 2012 2:27 PM

    First of all let's look at your environment ... a totally unpatched version of software that is so old it is in desupport mode. You should upgrade to a fully supported version but, if you can't, at least to 10.2.0.5.
    That said without seeing any of your code, or a listing showing permissions on the directory and files, there is insufficient information from which to help you.
    Please post ALL information required for us to understand what you are doing an your environment.
    But before I decided that NOBODY was doing anything ... I'd shell out to the server from SQL*Plus using the HOST command and verify that permissions are as you believe them to be. There is every reason to believe SQL*Loader is having an issue with your file as identified.

  • Trouble using Run Shell Script with python in Automator

    Hi. I have a python script I want to run in Automator (update_puzzles.py). All it does is check, rearrange and update files and there is not supposed to be any input. I can get the script to run outside of Automator, in Terminal, by navigating to the right directory and typing "python update_puzzles.py"
    I must not be setting up Run Shell Script correctly. I have it set to /bin/bash and Pass Input to stdin. The command line simply reads python /pathname/update_puzzles.py (where pathname is the path to the .py file, which I got by dragging the file onto the Run Shell Script command window). There are no actions before this in my workflow and the action after is View Results.
    The log says Run Shell Script failed, and the error is "Traceback (most recent call last):"
    Any suggestions?
    Thanks so much.

    If the script is expecting to do stuff with files in the same directory as the executable, you will probably need to add a statement to change to the appropriate working directory. The shell used in the Automator *Run Shell Script* action is a generic one that does not share any of the environment variables that the Terminal uses.

  • Downloading shell scripts with safari changes filename

    Hi,
    When I download a shell script using Safari, the file is saved with a ".sh" at the end, even if the file doesn't have any extension. Is there a way to have Safari just same the file with the original filename and not add the ".sh"?
    Thanks,
    Allan

    Interesting that Safari even knows what a shell script is. Its just a text file, with the user's executable bit set. Curious. Does Safari assume any executable text file is something that should be run from the shell? That would be strange, as anything I pull off my FAT32 drive has the executable bit set, too (thanks, Windows).

  • Invoking shell script with mouse

    How to invoke a shell script on double clicking the script in graphcal mode?

    A couple of ways come to mind, but first make sure the script is executable:
    $ chmod 0755 script.sh
    and then:
    1) Move the file into ${HOME}/Desktop and it should show up on your background window. Right-click on its icon and make sure the "open with" pane uses the right shell interpreter. You should now be able to click on the script's desktop icon and see it run. Nautilus may ask if you want to run the script, run it in a terminal, or simply view it in an editor.
    or
    2) Move the shell script to a directory, perhaps ${HOME}/bin, and the right-click in one of the GNOME toolbars; I prefer the one at the top of the screen. Add to the panel a customer application launcher.
    HTH

  • Debug a shell script with awk problem

    Hi, Buddy,
    I try to run the below shell script which was borrowed from linux for load average check.
    #!/usr/bin/ksh
    # Set threshold for 1, 5 and 15 minture load avarage
    # configured for 12-processors system
    max_1=48
    max_5=36
    max_15=24
    # Set the string which appears before the load average in the uptime command
    load_text='load average: '
    #Email list
    mail_to=[email protected]'
    alert=n
    up=`uptime`
    # Parse out the current load average from the uptime command
    load_1=`echo $up | awk -F "$load_text" '{ print $2 }' | cut -d, -f1 | cut -d. -f1`
    load_5=`echo $up | awk -F "$load_text" '{ print $2 }' | cut -d, -f2 | cut -d. -f1`
    load_15=`echo $up | awk -F "$load_text" '{ print $2 }' | cut -d, -f3 | cut -d. -f1`
    # Set alert=y if any of the average are above their thresholds
    if [ $load_1 -ge $max_1 ]
    then
    alert=y
    elif [ $load_5 -ge $max_5 ]
    then
    alert=y
    elif [ $load_15 -ge $max_15 ]
    then
    alert=y
    fi
    # Send mail if the alert threshold was reached
    if [ ! $alert = n ]
    then mail -s "High load on `hostname`" $mail_to < `uptime`
    fi
    Now we run it in Solaris now, so when I run, can get error like
    $./monitor_load_average.sh
    awk: syntax error near line 1
    awk: bailing out near line 1
    awk: syntax error near line 1
    awk: bailing out near line 1
    awk: syntax error near line 1
    awk: bailing out near line 1
    ./monitor_load_average.sh[28]: test: argument expected
    ./monitor_load_average.sh[31]: test: argument expected
    ./monitor_load_average.sh[34]: test: argument expected
    I understand the problem, but stil a little difficult to edit awk clause to get right syntax, is there any buddy can help?
    Thanks a lot in advance.
    Jerry

    I don't have access to Solaris right now,but if i understand the [manpage |http://bama.ua.edu/cgi-bin/man-cgi?awk+1] correct , you can use only a character as field separator (-F), try to use /usr/xpg4/bin/awk instead, it is posix compliant version and should be mostly compatible to linux gawk.
    Besides that, you may probably find better support on unix/solaris forums with similar questions?
    Best regards
    Maxim

  • Unit shell script with Oracle

    Hi guys,
    I want learn Unix shell script related with oracle .
    Please give me the best help link
    Thanks and Regards

    Dear bharat,
    I could find few for you.
    http://orafaq.com/scripts/index.htm#UNIX
    http://examples.oreilly.com/unixoracledbapr/
    http://www.oracle.com/technology/oramag/oracle/06-linuxsupp/linux_shell.html
    -aijaz

  • Executing Unix shell scripts with DBMS_SCHEDULER

    I have the following Unix shell script create_backup_file.sh:
    #!/usr/bin/ksh
    /usr/bin/ssh [email protected] /usr/bin/touch/app_home/home/trotestbat/scripts/TRO_batch_complete_`date +%d-%m-%Y-%H%M`
    If I execute this from the command prompt it creates the file on the remote server.
    I've used dbms_scheduler to try and execute this from Oracle:
    BEGIN
    SYS.DBMS_SCHEDULER.CREATE_PROGRAM
    program_name => 'CREATE_TRO_BACKUP_FILE'
    ,program_type => 'EXECUTABLE'
    ,program_action => '/APP/TORPEDO/DTE/SCRIPTS/create_backup_file_tro.sh'
    ,number_of_arguments => 0
    ,enabled => TRUE
    ,comments => NULL
    SYS.DBMS_SCHEDULER.CREATE_JOB
    job_name => 'DTE.TESTAGAIN'
    ,start_date => TO_TIMESTAMP_TZ('2010/05/17 16:09:24.710789 +01:00','yyyy/mm/dd
    hh24:mi:ss.ff tzh:tzm')
    ,repeat_interval => NULL
    ,end_date => NULL
    ,program_name => 'DTE.CREATE_TRO_BACKUP_FILE'
    ,comments => NULL
    END;
    The problem I have is that scheduler executes the shell script and creates the file but it never completes the job. The status of the job is permanently 'RUNNING'. Why is the scheduler not returning a completed status?

    the "infinite" script is usually caused by a prompt (script pauses for a user input).
    Please keep in mind that executing script via scheduler is not the same as manually via prompt.
    1. the script runs as ORACLE user ID (or whatever you specified using DBMS_SCHEDULER.create_credential or/and "$ORACLE_HOME/rdbms/admin/externaljob.ora")
    2. the environment variables are probably not the same.
    My wild guess is that you never ran SSH using "oracle" UID and thus it prompts for permission to add the remote computer’s fingerprint to the user’s ~/.ssh/known_hosts file - since it is a script, it just hangs and waits for input.
    Did you try to login to unix box as oracle uid and run the script manually?

  • Unix Shell Scripts with Oracle

    Any body who can give me the link where I can find the Unix Shell Scripts to access the Oracle database and execute the stored procedures and cursors.

    Your unix script will contain (at appropriate places):
    sqlplus -s username/pasword@server @your_sql_Script_that_calls_the procedure.SQLor
    sqlplus -s / @your_sql_Script_that_calls_the procedure.SQL

  • Shell Scripts with File adapter

    Hi Everyone,
    Can we use shell scripts in File Adapter of XI.
    If yes can someone give me the configuration and any helpful blogs or links.
    Helpful answers will be rewarded points.
    Thanks,
    Rupash K

    Hi,
    you can just call the script in the File Adapter, before or after XI processing step.
    Nevertheless, sometimes it behavior different between to call the script as to typ the command directly on the channel configuration.
    Here is the [SAP official document|http://help.sap.com/saphelp_nw04/helpdata/en/84/e8763c997fda50e10000000a11405a/frameset.htm], it is quite easy to use. Just call the script as if you want to call it on the shell, you have to aware about the path and placeholder which you may want to pass the it as parameter to your script.
    Here are some more links
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/sapXIFileAdapterOSCommandLine+Feature
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/morewiththeFileAdapter
    regards,
    Hai
    Edited by: Hai Long on Nov 14, 2008 5:30 PM

  • Shel Scripting with programs.

    Hi,
    I am developing a script that invokes a program, and that program is going to prompt for some input every now and then based on some parameters.
    My script shall provide input to the program, automatically, by processing the text output by the program..
    say..
    when the program asks
    "username:" the script shall enter "griffin"
    "room number:" the script shall enter 23
    "what is the temperature at XX:XX hrs": the script shall refer to a file where a list of temperatures with corresponding times are present to give the appropriate answer.
    For this, my script must be able to process the text output/prompted by the program.
    How do I do this? Any help is much appreciated.
    Format of the file with temperatures may be considered as below...
    00:00-34
    00:01-23
    23:59-65
    But this is not the real problem I have... I have cited this only as an example.. My script must be able to give inputs to the program **dynamically**.
    **Dynamically** is the only question I have, for if the inputs to be provided and their ordering is same irrespective of the number of invocations, and they are known at the time of writing the script, I can write this way..
    sh <script_name>.sh << EOF
    <input#1>
    <input#2>
    <input#3>
    EOF
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Thanks,
    Aswani.

    You can do this with the expect command (http://linux.die.net/man/1/expect)

Maybe you are looking for

  • Image Capture doesn't recognize SD card

    In Tiger I would pop in my SD card into a reader in my pcmcia slot and image capture would read it as a device and I could then use it to embed color profiles etc. as it downloaded to the correct folder. Leopard's Image Capture won't recognize the ca

  • How to reschedule a meeting if you are not the organizer of meeting ?

    One User (say user-A) sends out a meeting invitation. Everyone accepts the same. Later, the meeting needs to be rescheduled but 'user-A' who sent out the meeting invitation is OoO. Is there a way out to do this from outlook / exchange ? Please sugges

  • Register the workflow in OIM11g(for custom approval)

    hi all I am working on Custom Approvals I have already build approval file. By using jdeveloper i opened that, and build it as Jar. My Question is when i start to register this jar file in OIM. I need following details name= category= providerType= s

  • Invoke subflow from method implementation of automatic activity

    Hi, I am able to invoke a process from automatic activity (Process Creation), but if I want to invoke it as a subflow i.e. (calling process wait for sub flow to return and the sub flow send back the result to the calling process), how can I do that.

  • The most growing index.

    Dear Gurus, How can I find the index which made yesterday the most growth? Meaning allocated a new big extent? Thanks!!!!