How to truncate text in a shell script? [SOLVED]

Here is my shell script...
#!/bin/bash
case "$1" in
artist) dcop amarok player artist ;;
title) dcop amarok player title ;;
esac
I want it to send the artist and title truncated if they are more than 20 characters and with a little '...' ellipsis at the end. Can anyone help me?
Last edited by tony5429 (2008-03-12 13:28:24)

This might be a starting point, even though I don't know the answer: http://developer.apple.com/documentatio … 03521-SW16 (gosh what a long URL)
edit
wow, I was slow
Last edited by finferflu (2008-03-11 20:52:38)

Similar Messages

  • How to execute sql-queries through shell scripting in linux?

    How to execute sql-queries through shell scripting in linux?

    http://www.oracle.com/technology/pub/articles/saternos_scripting.html
    Two simple examples:
    #!/usr/bin/env bash
    set_orafra () {
       orafra=`echo 'set heading off
       select name from v$recovery_file_dest;
       exit' | sqlplus -s / as sysdba`
    set_orafra
    echo $orafra
    #!/usr/bin/env bash
    export ORACLE_SID=instance_name
    export ORACLE_HOME=/path_to_oracle_home_directory
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    export PATH=/$ORACLE_HOME/bin/$PATH
    $ORACLE_HOME/bin/sqlplus -s <<EOF
    connect scott/tiger@my_instance_name
    INSERT INTO table VALUES (sysdate);
    exit
    EOFEdited by: Markus Waldorf on Sep 17, 2010 12:19 AM

  • Echo colored text in a shell script?

    As part of a shell script I'm working on, I want to be able to print colored (preferably red) text to the Terminal window, to provide warnings to the user.
    How can I code in echoing colored text?
    (I did some googling and couldn't find anything that seemed to apply to what I want to do.)
    Any help would be appreciated!
    Thanks in advance!

    The following is a shell script that displays the terminal colors and the escape sequences used to generate them:
    #!/bin/sh
    # colors.esc - display the terminal colors and the escape sequences that
    # generate them. "Blink" is _NOT_ shown, as it is a very
    # annoying effect, and should be avoided at all costs in normal
    # daily uses.
    # Usage: colors.esc [12 character or less display string]
    # Bob Harris
    E=$(printf ' ') # escape <E>
    R="${E}[0m" # reset <E>[0m
    typeset dsp_str=""
    typeset dsp_txt
    typeset fg_text
    typeset bg_text
    if [[ $# != 0 ]]; then
    dsp_str=$(printf "%12.12s" "$*")
    fi
    color=(Black Red Green Yellow Blue Magenta Cyan White)
    for bg in "" 0 1 2 3 4 5 6 7 # for each background color
    do
    b=$bg && [[ X$b != X ]] && b="4$b;" # deal with no background color ""
    echo " ------------ ----bold---- -underline-- --reverse---"
    for fg in 0 1 2 3 4 5 6 7 # for each foreground color
    do
    f="3$fg" # setup foreground color
    line=""
    for a in "" 1 4 7 # for each attribute
    do
    [[ X$a != X ]] && a=";$a" # deal with no attribute ""
    if [[ -z "$dsp_str" ]]; then
    dsp_txt=$(printf "%12s" "<E>[${b}${f}${a}m") # build esc text
    else
    dsp_txt="$dsp_str" # use supplied text
    fi
    line="${line}${E}[${b}${f}${a}m${dsp_txt}${R} " # build entry
    done
    fg_text=$(printf "%-7s" ${color[$fg]}) # translate foreground color
    bg_text=$(printf "%-9s" "Bg${color[$bg]}") # translate background color
    [[ X$b = X ]] && bg_text=$(printf "%-9s" " ") # no bckgnd color
    line="$bg_text $fg_text $line" # build final display line
    echo "${line% }" # display the colorized line
    done
    done
    echo " ------------ ----bold---- -underline-- --reverse---"
    bg_text=$(printf "%-9s" " ")
    fg_text=$(printf "%-7s" "Reset")
    dsp_txt=$(printf "%12s" "<E>[0m")
    line="$bg_text $fg_text $dsp_txt" # build final display line
    echo "${line% }"

  • How to prevent Automator's "run shell script" to create fully decomposed forms of my strings ?

    I am using Automator's "run shell script" and I am seeing that it outputs fully decomposed forms of my strings.
    For example, when I set the action to "echo été" in a service (with "Replace selected text" activated) and run that into a Textwrangler window, I'll get fully decomposed forms that Textwrangler won't understand. But when I simply type that command into Terminal, I get my string in composed form.
    The problem is not the display issue, but the fact that if I want to run grep for example in "run shell script", I will not be able to find the proper strings since the forms are different.

    Originally I was using $@ to parse a string and get the result pasted by the service. That was a while ago. There, I noticed that some Japanese characters were messed up. Basically all the kana characters that come with voicing markers like が-ga (instead of か-ka) etc. I did not have the time to pursue that issue though.
    Then, last night, I found that a colleague of mine had tried to use $@ to feed to a local dictionary application called ding (http://ftp.tu-chemnitz.de/pub/Local/urz/ding/). His problem was with characters that had umlauts. After verifying how he wrote his action I remembered that I had similar issues with Japanese.
    Basically his command was "/path/to/ding $@"
    That's supposed to use the selected string as an argument to pass to ding, which will launch a Wish application where the string is used as the searched item.
    From Terminal, that works a treat. But the exact same line in Automator (with input as argument, not as stdin) messed the composition and the resulting string was not recognized by ding as a match to what it was supposed to match.
    So, I tried a few things to get to the core of the issue and found that a simple "echo [accented characters]" was enough to reproduce the difference in string handling between Automator and Terminal. That difference is also reproduced on a number of person's machines.
    I have a number of services that basically revolve on "run shell script" actions and involve 3rd party application outputs, preference files etc. so it would not be convenient to show that to you.
    I have sent a mail about this issue to the automator list yesterday too:
    http://lists.apple.com/archives/Automator-users/2011/Jun/msg00004.html

  • 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

  • How to end text element in sap script

    how to end an text element in sap script
    this is the format.
    /E text element name
    &tablename-fieldname&
    text-text-text-text
    now if i do not end that text element it is not displayiny my below text , so what to do in this case

    Go through the links mentioned below.
    http://www.****************/Tutorials/Smartforms/SFMain.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3c5d9ae3-0501-0010-0090-bdfb2d458985
    http://www.sapmaterial.com/smartform_example.html
    Re: Hands on SAP Smart Forms
    smartforms
    Reward points if useful.

  • How to avoid password prompt in shell script for zip password protection

    Hi
    I am trying to set password protection to my oracle database export backup. Once the backup completed, it should compress with a password protection. Thats the plan. Initialy we were using the gzip for the compression. Then realized that there is no password protection for the gzip. Started using zip option. I tried using
    zip -P <password> filename
    But it was throwing below error.
    -bash-3.2$ zip -P expreports REPORTS_2013FEB14.dmp
    zip warning: missing end signature--probably not a zip file (did you
    zip warning: remember to use binary mode when you transferred it?)
    zip warning: (if you are trying to read a damaged archive try -F)
    zip error: Zip file structure invalid (REPORTS_2013FEB14.dmp)
    Not quite sure why.
    Then I used zip -e REPORTS_2013FEB14.dmp.zip REPORTS_2013FEB14.dmp
    But this prompting for the password. As I am trying to put the command in the script. It will be tough if it prompts for the password.
    I would like to know how to avoid the password prompting by saving somewhere or how the code should be written. Tried using expect feature of shell script. Below was the code I tried. It didnt work.
    [oracle@SF40V6636 test]$ cat repexp.sh
    zip -e REPORTS_imp.log.zip REPORTS_imp.log
    expect "Enter password:"
    send "imprep"
    expect "Verify password:"
    send "imprep"
    So please help in avoiding this password prompt or let me know how to change the code.
    Thanks
    SHIYAS M

    How about using gpg and adding a secret key to the requirement of a password? No one should be able to decrypt your file, not by knowing only the password.
    1. Generate a public and private key pair:
    $ gpg --gen-key
    When it shows "We need to generate a lot of random bytes…" open another terminal session and type "dd if=/dev/sda of=/dev/null" to create traffic. When the public and secret key created and signed you can Ctrl-C the dd command.
    To see what you have created:
    $ gpg --list-keys
    2. Encrypt and gzip your stuff:
    $ tar zcf stuff.tgz file_or_folder
    $ gpg recipient "Some Name" encrypt stuff.tgz
    $ rm -f stuff.tgz
    3. Decrypt and extract the archive:
    $ gpg batch yes --passphrase "password" -d stuff.tgz.gpg > stuff.tgz
    $ tar zxvf stuff.tgz
    Again, knowing the password alone will not let anybody decrypt your stuff.

  • How to use encoded password in shell script ?

    Hi everybody,
    For make a load file in oracle table, I'm using a LKM File to Oracle updatding with a sqlldr (shell script).
    My problem is very simple : For security reason in this shell-script , I don't want to see in clear the password of the Oracle user for database connection. Is it possible and how do it ?
    Thanks in advance

    Hi-
    Yes it is possible by the way of KM custamization, You need to modify LKM call sqlldr via jython step to pass the user info and password as variable instead of ODI method. Try this command in your KM step:
    userid=#GLOBAL.user/#GLOBAL.psw
    Hope this will work for you.
    Thanks,
    Saravanan Rajavel

  • How to prepare for Converting UNIX shell scripts to PL/SQL

    Hi All
    I was said, that i may have to convert a lot of unix shell script to PL/SQL, what are the concepts i need to know to do it efficently,
    what are the options PL/SQL is having to best do that.
    I know the question is little unclear, but I too dont have much inputs about that i'm sorry for that, just its a question of how
    to prepare myself to do it the best way. What are the concepts i have to be familiar with.
    Many Thanks
    MJ

    Just how much work is involved, is hard to say. Many years ago I also wrote (more than once) a complete ETL system using a combination of shell scripts, SQL*Plus and PL/SQL.
    If the PL/SQL code is fairly clean, uses bind variables and not substitution variables, then it should be relatively easy to convert that PL/SQL code in the script to a formal stored procedure in the database.
    There is however bits and pieces that will be difficult to move into the PL/SQL layer as it requires new software - like for example FTP'ing a file from the production server to the ETL server. This can be done using external o/s calls from within PL/SQL. Or, you can install a FTP API library in PL/SQL and FTP that file directly into a CLOB and parse and process the CLOB.
    Think of Oracle as an o/s in its own right. In Oracle we have a mail client, a web browser, IPC methods like pipes and messages queues, cron, file systems, web servers and services, etc. And PL/SQL is the "shell scripting" (times a thousand) language of this Oracle o/s .
    In some cases you will find it fairly easy to map a Unix o/s feature or command to one in Oracle. For example, a Unix wget to fetch a HTML CSV file can easily be replaced in Oracle using a UTL_HTTP call.
    On the other hand, techniques used in Unix like creating a pipe to process data, grep for certain stuff and awk certain tokens for sed to process further... in Oracle this will look and work a lot different and use SQL.

  • How to replace a word thr shell script

    Hi,
    I need a shell script which should read a file(a.txt)
    and need to update the same file( means only replace a word with another one in the same file)
    my unix version is SunOS and i am using ksh
    could you pls provide me some better way.
    My failured trails are as below
    suppose a.txt file having data like,
    column1 column2 column3
    data1 data2 data3
    and my script is,
    #!/usr/bin/ksh
    patha=/tmp
    filea=a.txt
    sed '/column2/s//column4/g' $patha/$filea > $patha/$filea
    And also pls provide how to add data(data into new line) into file(a.txt)
    Thanks in advance.

    This is an Oracle SQL and PL/SQL forum.
    If you want to learn how to write unix shell scripts I suggest you search the internet for a suitable unix forum.

  • How to call a procedure from  Shell Script

    Friends,
    How can i call a procedure from a shell script ? If any one know the answer , let me know immediately .
    Thanks in advance .
    Chakks

    We connect using SQLPlus commands on the Unix server:-
    Our code block is below:- We've got DBMS_OUTPUT in the procedure, hence the spooling. You don't need all this, but you do need the sqlplus directory, etc... in your profile.
    sqlplus -s <<EOF > ${CREATE_LOG_FLE}
    $UserName/$Password@$SID
    SET SERVEROUTPUT ON SIZE 1000000;
    spool ${CREATE_LOG_FLE}
    EXECUTE $STORED_PROC(${Months}, ${DeleteRecords});
    EOF
    Hope that helps

  • How do i print parameters in shell script through java

    Hi,
    I am sorry if have posted this query in wrong thread!!!
    How do i print the parameter in shell script which are passed from java programm?
    i have tried in different ways.. but the actual param value is not printing when i execute the java programm
    java code is here
    import java.io.IOException;
    public class TestShell {
          * @param args
    public static void main(String[] args) {
             String inputFilePath=args[0];
              String inputFileName=args[1];
              String outputFileName=args[2];
              String outputFilePath=args[3];
              Runtime r = Runtime.getRuntime();
              String[] cmdArray = new String[]{"Test.sh",inputFilePath, inputFileName, outputFileName, outputFilePath};
              try {
                   r.exec(cmdArray);
                   System.out.println("Test.sh executed successfully.");
              } catch (IOException e) {
                   e.printStackTrace();
    }I need a shell script to print paramenters (inputFilePath, inputFileName, outputFileName, outputFilePath)
    Thanks,
    Jasmin

    user13836688 wrote:
    But my code is something look like thisWell unless I've completely lost my marbles (possible) or Java Runtime.exec() does something I've never heard of, I can't even see how that will execute. For a start, assignments in the Bourne shell take the form ofinfile = $inputFilename;orinfile = "inputFilename";not what you've got; and the first form would only work if you've set the appropriate environment variables.
    Are you sure you're not confusing this with a Javascript script?
    Winston
    Edited by: YoungWinston on Apr 18, 2011 12:51 PM
    And BTW, you don't need to put ';' at the end of each statement, unless there's more than one on a line.
    Edited by: YoungWinston on Apr 18, 2011 12:54 PM
    BTW2: 'printf "%d", inpath' also looks very dodgy, since 'inpath' is unlikely to be a number (in fact, it's unlikely to be anything).
    I think you might want to get a book on scripting.

  • How To Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • How to detect a system crash (shell script)

    what is the easiest way to find out if the system has previously crashed or been powered off without a clean shutdown?
    i am looking for a way to be used in a unix shell script. is there e.g. a specific text i can look for in a specific logfile?
    a panic.log might not be enough because in case of power failure the system will not have time to write to that logfile.
    any help is greatly appreciated.

    The shutdown codes are not documented anywhere that I know of. I've seen these mentioned, but I don't know whether they're all accurate.
    -128: Battery or UPS dead (?)
    -62: PMU did not detect heartbeat (PPC Xserve)
    -60: Thermal (?)
       0: Low power
       3: Forced shutdown
       5: User requested restart or shutdown

  • How to Call Multiple Sessions through Shell scripting

    Dear Members,
    I have a scenario where I load data into target table from 20 different source tables.
    For this I have written three procedures where there exists an bulk insert executed on a same table in every procedure. Now I have to call these procedures simultaneously so that
    all three bulk loads are executed at once in different sessions.
    For this I have to write a shell script which opens 3 different sessions and execute all these packages at once.
    Can you guide me through.

    When you call sqlplus in your shell script, put a & at the end so that it runs the SQL scripts in the background. For instance:
    #!/bin/bash
    ...oracle home stuff
    $ORACLE_HOME/bin/sqlplus user/pass @script.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script2.sql &
    $ORACLE_HOME/bin/sqlplus user/pass @script3.sql &

Maybe you are looking for

  • Let me choose which font(s) to substitute when opening an Adobe Illustrator (CS5) file

    Hello! I have an illustrator Windows file, created by someone else, and one font is missing. When I open the file, Illustrator says a font is missing and it will substitute the missing font. How can I tell Illustrator to use a specific font instead o

  • My PDF did not covert the whole page!

    When I opened the document in Microsoft Word only half of the information was there. I attempted to do it a second time and same results.  I then converted another PDF from the same site and that one converted properly, what do I do? Deederdoos15

  • Oracle Query output erro (MX7)

    Hi Coldfusion page throwing ODBC error when Oracle (9i) Query executed. No useful error message shown. Same query gets executed successfully in Oracle Client. When i use CLOB Column type in my select query error has shown. In the same query i have us

  • ONE ROW PER TYPE

    Hi , I have go three tables. personnel, Personnel_degree, and code_types here is how they are related . Personnel Stores the person informations like id,name etc. Personnel_degree stores personnel_id, degree_id, , degree_date and code_types stores th

  • How can I change the default templates to from A4 to Letter US?

    Hi, I live in Québec, the french part of Canada. Because I use French, iWork think I leave in France, so the default templates are in A4. How can I change the default templates to from A4 to Letter US? It seem's impossible. In Pages 06, each language