Complex shell script command

HI Experts
can anybody know what this complex shell script command is doing .. i know its looking for some character at some point but exact explanation will be good for learning.
egrep "^.{292}[CFOPRA][EPR]$" dn.dat
Thanks

A simple example can often demonstrate how things work:
# cat sample.dat
xABCDE1
xABCDE2
ABCDE3
ABCDE4
xDBCEA5
xDBCEA6
# egrep "^.A" sample.dat
xABCDE1
ABCDE4
Above matches lines that begin with any character followed by an "A".
# egrep "^.{2}A" sample.dat
xABCDE2
Above matches lines that begin with any 2 characters followed by an "A".
# egrep "^.{2}[AD]" sample.dat
xABCDE2
xDBCEA6
Above matches lines that begin with any 2 characters followed by an "A" or D".
# egrep "^.{6}[345]$" sample.dat
ABCDE4
xDBCEA5
Above matches any lines ending with "3", "4" or "5",
provided it's the 7th character.
# egrep "^.{5}[345]$" sample.dat
ABCDE3
Above matches any lines ending with "3", "4" or "5",
provided it's the 6th character.
# egrep "^.{6}[EA][26]$" sample.dat
xABCDE2
xDBCEA6
Above matches any lines ending with combinations of "E2, E6, A2, A6",
provided the combination starts at character position 7.
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Which .bash does "do shell script" commands use?

    The "do shell script" command uses the Bourne shell "sh". But I am curious to know which .bash it uses to define the shell environment variables.
    I ran into a problem installing a third-party unix program which required new environment variables to be defined in order to execute. Defining these variables and executing this program from the terminal worked fine.
    But executing it within a "do shell script" command in an Applescript - the program died silently because the environment variables it required were not defined in the shell Applescript uses. It appears to invoke a new shell which does not inherit the environment variables defined in your home user shell.
    (I found this out by 'do shell script "set"' which listed the environment variables Applescript knows about - the ones I defined for the third-party program were not listed).
    A "brute force" way of fixing this is to pass the environment variables directly:
    do shell script "export THIRDPARTY_ENVVAR=blah; /usr/sbin/thirdpartyprogam"
    This works but not exactly elegant, particularly when you need to pass a number of variables.
    So - any better ways to do this? Can I edit the .bash Applescript uses, and where is it?
    Thanks.

    Another option that might work for you... if you are saving/distributing your AppleScript as an "Application bundler" is to group all your shell env. variables and other commands into a separate shell script file. Then include the shell script inside your app bundle. Locate the shell script at runtime and run that with "do shell script".
    For example, create "myShellScript.sh"
    #!/bin/sh
    export THIRDPARTY_ENVVAR=blah
    # ... more variable declarations..
    /usr/sbin/thirdpartyprogam
    # ... more shell commands...
    Store the shell script file inside your AppleScript bundle's Contents -> Resources folder (remember to make the shell script executable). Then your AppleScript can find your shell script at runtime and execute it like this:
    set ssPath to quoted form of POSIX path of (path to resource "myShellScript.sh")
    set stdout to do shell script ssPath
    Steve

  • Wait for a "do shell script" command to finish

    i have an applescript that has to call a few external applications. i currently do this by setting the exact syntax of the external command in a string variable, then issue a "do shell script cmd" (seen many examples across the net using this standard)
    my applescript continues beyond these commands. how do i set the applescript to either wait for the above external command to finish, or not?
    regards
    jingo_man

    Usually AppleScript will wait for a shell script to complete before it continues, but adding an ampersand (&) at the end of the shell script command will make it run in the background, which allows the AppleScript to continue. See Technical Note 2065: do shell script in AppleScript for more information.

  • Beginner question - testing for null string from shell script command

    I'm trying to test the result of a shell script command. I want to put out a message if the result is a null string. At present I get this applescript error "The command exited with a non-zero status"
    I'm sure this is a simple question ... but I can't figure out how to do it. Help!

    You can use try clause for the problem:
    set _result to ""
    try
    set _result to do shell script "/blah/andblah"
    end

  • Passing dialog text to a shell script command

    Hi. Newbie here. I got a good book, will learn this sooner or later.
    But right now, I got a problem I can't figure out
    I'd like to display a dialog box that requests some text. I'd then like to use that text as the variable for a shell commmand.
    Let's say for instance that I want to prompt for the asset tag number of the machine and want the result to end up in the ARD Info 1 field. I've got the first and third line, just don't know how to "place" the captured text:
    display dialog "What is this Mac's assett tag number?" default answer ""
    do shell script "defaults write /Library/Preferences/com.apple.RemoteDesktop Text1 <resultfrom_dialoghere>"
    Anyone?
    Darrin

    You use text returned of:
    dialog reply n : Reply record for the ‘display dialog’ command
    properties
    button returned (Unicode text, r/o) : name of button chosen (empty if ‘giving up after’ was supplied and dialog timed out)
    text returned (Unicode text, r/o) : text entered (present only if ‘default answer’ was supplied)
    gave up (boolean, r/o) : Did the dialog time out? (present only if ‘giving up after’ was supplied)
    ex:
    set _result to text returned of (display dialog "What is this Mac's assett tag number?" default answer "")
    do shell script "defaults write /Library/Preferences/com.apple.RemoteDesktop Text1 " & quoted form of _result

  • Automtor shell script "command not found"

    I want to include the execution of a shell script in Automator. The script just executes a third-party application (actually, pdftk) with certain parameters. I have written the script, saved it in my Home directory as "foo.sh", made it executable, and can correctly call it from Terminal with ./foo.sh. It works as expected.
    But if I include it in Automator's workflow, into action "Run shell script", its execution breaks complaining that "pdftk: command not found". This indicates that the script is correctly found and read by Automator. How is it, that Terminal's bash can find the command, but Automator doesn't ? Have commands to be written in a special way to be understood by Automator ? Perhaps third-party commands are not allowed in Automator ?

    As twtwtw has said, you environment when running Automator is NOT the same as when you are in a Terminal session.
    pwd:
    /Users/harris
    /bin/ls -dlaeO@ .
    drwxr-xr-x  349 harris  harris  - 11866 Mar 14 22:06 .
    id -a:  uid=501(harris)
    gid=501(harris)
    groups=501(harris),
    204(_developer),
    100(_lpoperator),
    98(_lpadmin),
    80(admin),
    61(localaccounts),
    12(everyone)
    $# 0
    printenv: SHELL=/bin/bash
    TMPDIR=/var/folders/zv/zvU6+bMiHTeElG+JIWOdzk+++TI/-Tmp-/
    Apple_PubSub_Socket_Render=/tmp/launch-rVMvHQ/Render
    USER=harris
    COMMAND_MODE=unix2003
    SSH_AUTH_SOCK=/tmp/launch-fH4Gt7/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0:0
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    PWD=/Users/harris
    DBUS_LAUNCHD_SESSION_BUS_SOCKET=/tmp/launch-RIPIu6/unix_domain_listener
    SHLVL=1
    HOME=/Users/harris
    LOGNAME=harris
    DISPLAY=/tmp/launch-ttdbVO/org.x:0
    FRED=3-Mar-2009
    _=/usr/bin/printenv

  • Shell scripts commands

    Hello.
    I'm having my first contact with Oracle Retail and I'm doing some shell scripts to extract/transform/load data.
    I was checking some scripts and I saw some commands as rmse_terminate, message, verifybinary, _call.
    Do you know where I can find some document explaining these commands and providing others if exist?
    Today I'm working with AIP, RDF and RMS.
    Let' me know if you can provide me a link or other path where I can find the document
    Thanks
    Edson

    Hi Ahmed,
    Can you please mention the names of the scripts where you found these calls, and the application to which those scripts belong to?
    Erik

  • Shell script Command Merge

    Can anyone help me to merge two commands into a single command
    1. cd ../../https-eportaldevw5/logs | cat pid
    2. ps -ef | grep $pid
    note-This $pid will be the output of command 1

    Thanks.. that was really helpful to me..
    one more question..
    when I am executing multiple commands one after another in a single go then one of the in-between command is not executed and skipped without execution.
    Example:
    echo "************************ SCC *****************************" > /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw5/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GLS ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw3/logs/pid) >> /tmp/output/op1.txt
    echo "****************** TE Corporate ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportalpoc/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GCT ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw1/logs/pid) >> /tmp/output/op1.txt
    echo "****************** eCommerce ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw6/logs/pid) >> /tmp/output/op1.txt
    echo "****************** IMO ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw7/logs/pid) >> /tmp/output/op1.txt
    echo "****************** ADR ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw8/logs/pid) >> /tmp/output/op1.txt
    echo "****************** Corporate Trust Portal Server ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw13/logs/pid) >> /tmp/output/op1.txt
    echo "****************** Corporate Trust App Server********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw14/logs/pid) >> /tmp/output/op1.txt
    echo "****************** GMW ********************" >> /tmp/output/op1.txt
    ps -ef | grep $(cat /opt/netscape/iPlanet/https-eportaldevw4/logs/pid) >> /tmp/output/op1.txt
    cat /tmp/output/op1.txt
    In above example,
    echo "****************** Corporate Trust App Server********************" >> /tmp/output/op1.txt
    this command is skipped when I am executing all commands in a signle go..
    Can anyone suggest me anything in this.

  • How to do multiple shell scripts in AppleScript

    I got some solutions from previous posts on how to run sudo in Applescript, but there is still some minor syntax issues when I try to get to the destination directory. Usually in shell script I just type
    cd directory-destination
    in several lines to batch process those commands, but when I work with applescript, if I do do shell script for every "cd" command, instead of getting an overall result, I would get intermediate results individually.
    I read doc and learned that there might be a way to put commands together by using the & sign?
    Message was edited by: ttback

    An individual do shell script command runs in its own shell, so to perform multiple commands within that shell you need to combine them into a single statement. You can use the ampersand '&' operator to concatenate text strings, and the semicolon ';' to separate the commands, for example:set theFolder to "/Applications"
    do shell script "cd " & theFolder & "; ls -l ."See the technical note do shell script in AppleScript.

  • Startup shell script help for newbie?

    New to UNIX (linux)... need the bash shell script commands for my r.c local file to start my services when server boots.
    I got my ds, dps and admin server in their respective /opt directories. I need the shell commands to have these start. Of course I can start them manually but when I try a line like this in a script, it doesnt work:
    ./var/opt/sun/directory-server/slapd-dsserver/start-dsserver
    Some path problem or dot thing?

    There are a few other things you may want to consider, such as what the default browser is, are tabs being used, is the page loaded yet, etc, but Safari has a do javascript command in it's scripting dictionary. The following script will open a new document and run your specified javascript, or you can go to their NPR Program Stream Page and download a playlist that will run directly from iTunes.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 335px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set my_script to "NPR.Player.openPlayer(2, 0, '03-21-2008', NPR.Player.Action.PLAY_NOW, NPR.Player.Type.PROGRAM, NPR.Player.Mode.LIVE)"
    tell application "Safari"
    activate
    set the URL of the front document to "http://www.npr.org/"
    if my page_loaded(20) is false then error numner - 128 -- page not loaded in time
    do JavaScript my_script in document 1
    end tell
    on page_loaded(timeout_value) -- from http://www.apple.com/applescript/archive/safari/jscript.01.html
    delay 2
    repeat with i from 1 to the timeout_value
    tell application "Safari"
    if (do JavaScript "document.readyState" in document 1) is "complete" then
    return true
    else if i is the timeout_value then
    return false
    else
    delay 1
    end if
    end tell
    end repeat
    return false
    end page_loaded
    </pre>

  • Input to a shell script

    Hey guys,
    I was wondering let's say I have a text field called "text field"
    I need the contents of it on a click of a button to go to a do shell script "stuff stuff/ stuff stuff/ (content from text field here)/ stuff stuff" Some thing of this sort. Hope this makes sense, Thanks a lot, Max

    Thanks for the response Ed! I still can't seem to get it to work. Let me explain in a little more detail what I need to happen, any help would be great!
    I have an app that starts a server from a do shell script command.
    It technically never ends, and it it constantly outputting data. As a result when I run the program, the server starts and runs fine, but the program locks up because it is waiting for the command to end. Is there a way I can get the data to go somewhere, I don't need to look at it so it could just disappear.
    Here is my code:
    on clicked theObject
    if theObject is button "Start" of window "Window" then
    set serverName to content of text field "servername" of window "Window"
    set adminPass to content of text field "adminpass" of window "Window"
    set serverPassword to content of text field "serverpassword" of window "Window"
    set botsTrue to state of button "bots" of window "Window"
    set statsTrue to state of button "stats" of window "Window"
    set serverPass to state of button "serverpass" of window "Window"
    set shellScript to "/Applications/Zap\\!\\ Folder/ZAP.app/Contents/MacOS/ZAP -dedicated -hostname " & serverName
    set shellScript to shellScript & " -adminpassword "
    set shellScript to shellScript & adminPass
    if botsTrue = 1 then set shellScript to shellScript & " -bots"
    if statsTrue = 1 then set shellScript to shellScript & " -stats"
    if serverPass = 1 then set shellScript to shellScript & " -password "
    if serverPass = 1 then set shellScript to shellScript & serverPassword
    do shell script shellScript
    display dialog shellScript
    end if
    end clicked
    Thanks a lot!

  • How does one run a shell script at system startup?

    Hi,
    I am trying to unmount my Boot Camp hard drive on my MacBook Pro. Now what I could do is create an automator action, save it as an application and then put it into my user´s login items. I am wondering though - shouldnt it be possible to run a simple shell script command like +diskutil unmount /Volumes/"Boot Camp"+ sometime during the startup process?
    Or to put it another way - is there an easy way to do this or do i have to create an manage a daemon through launchd ?
    Your help is very much appreciated.

    sorry I forgot to mention that there is a bug in Lingon which creates a plist incorrectly if you enter your script explicitly on line 2. At least I haven't been able to make it work. A workaround I always use it the following.
    Save your script as a *plain text* file from your favorite text editor. change the extension to .sh and make the file unix executable. Now, when you ccreate a launch daemon using Lingon, enter the path to that file instead of the script itself.
    This always works for me.
    Good luck!

  • 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.

  • AppleScript syntax do shell scripts

    Hi guys,
    i am having endless issues with the syntax of the following applescript. Please help me and i'll make you my new god, cheers. The
    applescript syntax is:
    tell application "Finder"
      display dialog ¬
                        "Select Output Source" buttons {"Computer", "TV"} default button "TV"
              set InternalSpeakers to (do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'")
      --InternalSpeakers is now a variable which changes the sound output to Computer
              set HDMI to (do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Soundflower (16ch)'")
      --InternalSpeakers is now a variable which changes the sound output to TV
              if button returned of result = "Computer" then InternalSpeakers
              if button returned of result = "Computer" then HDMI
    end tell
    at the moment i am getting the following error:
    I have tried arranging and re-arranging the applescript to no avail, please help me

    You're over complicating the situation. This
    set InternalSpeakers to (do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'")
      --InternalSpeakers is now a variable which changes the sound output to Computer
    sets InternalSpeakers to what the do shell script returns. It does not set InternalSpeakers to hold the do shell script command to run when you access the variable. There are ways to do this but its not needed here. Just do thsi as a simple if then else
    display dialog ¬
                        "Select Output Source" buttons {"Computer", "TV"} default button "TV"
    if button returned of result = "Computer" then
         do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Built-in Output'"
    else    if button returned of result = "TV" then
        do shell script "cd ~/Downloads/SwitchAudioSource-v1; ./SwitchAudioSource -s 'Soundflower (16ch)'"
    end if
    Something like this will work.  Also there is no reason for the code you show to do it in a tell block. The Finder isn;t needed for this.

  • Shell script to logout?

    Hello, I am working on an automator app that will quit all apps (which works very well), pause for several seconds and then logout a user. Right now, I am having to use the "watch me" to log out, but, it is not totally consistent in the action. Is there a shell script command?
    Thanks

    So, call me a picky, 'my system has to be just so' kinda guy... But I've got 5 users on my iMac. The wife and three kids. The kids have time limits on their accounts....
    Here's the thing with the time limits parental controls. It doesn't actually log out the user. (I guess that's to prevent lost documents etc.)
    Sounds nice, right? Well... check this out. My kids have parental controls on cause they REALLY like to play world of warcraft. For HOURS. So... WOW has this nice feature that doesn't let you exit the program nicely when you're in 'combat'. So, if you're in combat, and you run out of time with parental controls, the computer doesn't put the user back to the login screen. My kids have figured this out and will play for 15 hours at a stretch if we let them. (I think they should be allowed to play for a little extra time for figuring out how to beat the parental controls, but the wife disagrees)
    I remember way back when with 10.5.0 WOW and Parental controls didn't get along. -There's gotta be a relationship to this behavior.
    Anyways... Back to the problem. I'm at the login screen and no password for the kids account. Assume I can't log them in to log them out. (there's 4 users anyway - it would take too long)
    Okay then... Assume I'm logged into my user account (an admin account on the computer) and I see that there's 5 users logged in. Myself, my wife, and my 3 kids by typing users or w in the terminal. The parental controls have left my users logged in. So I pull off a killall -u username command in the terminal. I've found that this doesn't actually log out users, it just kills all their processes.
    When I type users or w in the terminal it shows me that there's indeed still 5 users logged in. The activity monitor as well tells me that there's no processes active that belong to anyone but me, and root. Yet the shell tells me that there are still users active.
    I KNOW there's a unix command that will log out a user, but no one will share this secret! It's not anywhere on the web. I've been looking for weeks!
    The reason I know, is that there's a command in Apple remote desktop to force users to log out.... Not only that, but it does it in a way that doesn't kill the loginwindow or the WindowServer processes.
    Someone PLEASE type the wee command that it takes to do this seemingly 'easy as two clicks' task.
    -Graham

Maybe you are looking for