Shell Script to compare files

Hi All,
Below is the sample script used to compare two files, this can be enhanced further.
DATE=`date +%Y%m%d`
TIME=`date +%H%M%S`
count = 0
echo "Provide the TOP (e.g. XXFIN)" #| ${TEE}
read TOP
echo "Provide the inputs from these: FORMS or REPORTS or JAVA or XML or ADMIN_SQL or TEMPLATES"
read TYPE
FILE=${TOP}_${TYPE}_Compare_File_Results_${DATE}${TIME}.log
TEE="tee -a ${FILE}"
echo "##########################################################################################################################" | ${TEE}
echo "File Comparison Type if Binary provide 'B' or 'O':" | ${TEE}
read file_type
echo file_type
echo "Provide Production file path:" | ${TEE}
read prod_path
echo "Provide Fix file path:" | ${TEE}
read fix_path
echo "You have provided Production file path as :$prod_path" | ${TEE}
echo "You have provided Fix file path as :$fix_path" | ${TEE}
echo "Compare Results will be shown in file:" | ${TEE}
echo "##########################################################################################################################" | ${TEE}
for release in `ls -R $prod_path`; do #`ls /app/ebs/atgsidev01/gsidev01cust/xxcomn/java/Test/1/`; do
if cmp -s "$prod_path/$release" "$fix_path/$release"
then
echo "TEST............="cmp -s "$prod_path/$release" "$fix_path/$fix" | ${TEE}
fi
     if [ -f $fix_path/$release  ]
     then
          echo #"File Exists...." >> Compare_File_Results.txt
     if [ 'B' -eq "$file_type" ];
     then
     if diff -q "$prod_path/$release" "$fix_path/$release" ;
     then
          echo #"The files match"$release
     else
          echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | ${TEE}
echo "File Name:"$release | ${TEE}
          echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | ${TEE}
     count=`expr $count + 1`
          echo "The files are different: "$release | ${TEE}
          diff -w "$prod_path/$release" "$fix_path/$release" | ${TEE};
     fi # End of if diff -q
     else
     if cmp -s "$prod_path/$release" "$fix_path/$release"
     then
          echo #"The files match"$release
     else
     echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | ${TEE}
echo "File Name:"$release | ${TEE}
          echo "==========================================================================================================================" | ${TEE}
     count=`expr $count + 1`
          echo "The files are different: "$release | ${TEE}
          diff -w "$prod_path/$release" "$fix_path/$release" | ${TEE};
          echo "==========================================================================================================================" | ${TEE}
          echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" | ${TEE}
     fi #End of if cmp -s
     fi #if [ 'B' -eq      
     fi # if [ -f
done
echo "##########################################################################################################################" | ${TEE}
echo "Count of files=$count" | ${TEE}
echo "##########################################################################################################################" | ${TEE}

Thanks Suraj!
;) AppsMasti ;)
Sharing is Caring

Similar Messages

  • Script to Compare File Contents in Two Folders and List Differences?

    I've looked through the Forum but can't find anything that seems quite to address my problem--and I'm really new to AppleScript, so please forgive me if this is a dumb question.
    I burn a great many files of varying kinds (InDesign, Illustrator, Photoshop, PDF, etc.) to DVD everyday as part of my job. It happens not infrequently, though, that files drop out in the process and don't make it to the disk, with the result that I get calls from Manufacturing saying that I've screwed up and that random files X, Y, and Z are not on the disk that I sent.
    I've tried various ways to failproof my burning routine, but utlimately, it seems like something still slips through sometimes--that is, the files are definitely in by Source Folder, but sometimes they don't leap the chasm to the disk. And since there can be several hundred files, it can be difficult to know at a glance if something is wrong.
    It would be extremely helpful if there were a script that I could run to compare the contents of the folder source on my desktop (just say its called "Source Folder") with the contents of a disk I have just burned (whose name might vary, but whose folder structure is a duplicate of the subfolders in "Source Folder" that I have burned to disk. All I need the script to tell me is if there are files in my desktop Source Folder than are not on the burned disk).
    Is this possible? I'd appreciate any help anyone could offer--right now, I'm printing up the disk directory and a list of the files from my desktop Source Folder and comparing them line for line, and my soul is dying.
    Please help!

    This can be pretty easily hacked together using a combination of AppleScript and shell scripting.
    There's a shell command diff that can tell if two directories are the same or not. You can use AppleScript to put a nice front-end on it, like:
    set src to (choose folder with prompt "Select the source directory")
    set dst to (choose folder with prompt "Select the destination directory/disk")
    try
      do shell script "diff -rq " & quoted form of POSIX path of src & space & quoted form of POSIX path of dst
    on error theErr
      display dialog "The following differences were found:" & return & return & theErr
      return
    end try
    display dialog "Directories match. No differences found"
    It's quick and dirty, but should get you started. It runs the diff command which triggers the 'on error' code if there are any differences. The script then reports the differences and exits. If there are no differences the 'on error' code is skipped and you get the all clear message.

  • Unix shell script to batch file for windows

    Hello all,
    Iam writing a program in java in unix environment and iam executing using shell scripts in unix this program is for client-server environment
    which look like this:
    For server:
    #! /bin/ksh
    export CLASSPATH=/user/vpp/jal/classes:$CLASSPATH
    #set var for filename config file
    export JAL_CONF_FILE=/user/vpp/jal/conf/JALapp.conf
    java -DJAL_CONF_FILE=$JAL_CONF_FILE jalsvr/JALTCPServer 7776for client side it is
    #! /bin/ksh
    export CLASSPATH=/user/vpp/jal/classes:$CLASSPATH
    echo $CLASSPATH
    java jalcl/JALTCPClient msoc05:7776my question is know i want to execute them in windows by creating batch files runsvr.bat, runcl.batbut how
    i gave PATH by giving JRE path but what is the replacement of export because iam having all class files
    in /jalcl for clients and /jalsvr for server but want to create this batch file in separate /bin folder how to do.please help me

    Thank you for reply ,
    And sorry by mistake question repeated twice,
    but when iam executing those batch files it is throwing some exceptions,
    in that file you did not mention to set the JRE path whether it is not necessary and also there msoc05 is the machine name of unix system that need to kept or need to be changed with window IP address .please reply.
    thanks in advance.

  • Unix Shell Script to check file Format

    Hello
    I am New to shell scripting.Please help me to write a script for the below condition.Any help is highly appreciated.
    I will get a text file every month like the one below
    Sample file
    Payslip.txt
    ========
    EMPID EMAIL PCTAG#
    4946:[email protected]:151207
    4978:[email protected]:154434
    5091:[email protected]:160784
    5208:[email protected]:153601
    5211:[email protected]:158963
    5218:[email protected]:156967
    5247:[email protected]:153760
    5250:[email protected]:160078
    5276:[email protected]:154693
    I should check for the below conditions in the above file
    Conditions:
    =======
    1.File should be seperated by colon(;)
    2.EMPID should not be null
    3.Email address and pc tag# should be null if it is missing
    4.No empty record should be there
    All the above four conditions should be checked
    If any one of four conditions are not met then the file is invalid and it should exit with status saying that file is invalid.
    If all the four conditions are met it should say that the file is valid
    Any help is highly appreciated.It is urgent.
    Thanks in advance
    Manoj

    Try this :
    error()
    {       echo -n "Line "$NR "  "$LINE "  "       >>$STATUS
            echo $1                                 >>$STATUS
    NR=0
    STATUS=/tmp/status.txt
    rm -f $STATUS
    cat Payslip.txt | while read LINE
    do
            NR=`expr $NR + 1`
            ### Check colons ###########
            if [ ! "`echo $LINE | grep :`" ]; then
                    error "No colon"
                    continue
            fi
            EMPID=`echo $LINE | awk -F: '{print $1}'`
            EMAIL=`echo $LINE | awk -F: '{print $2}'`
            PCTAG=`echo $LINE | awk -F: '{print $3}'`
            ### Check null line ###########
            if [ ! "$EMPID" -a ! "$EMAIL" -a ! "$PCTAG" ]; then
                    error "Null line"
                    continue
            fi
            ### Check null EMPID ###########
            if [ ! "$EMPID" ]; then
                    error "No Empid"
                    continue
            fi
    done
    echo
    if [ -f $STATUS ]; then
            cat $STATUS
            echo
            echo "File is Invalid"
    else
            echo "File is Valid"
    fi
    echo

  • Automator: shell script to change file permissions

    Hey guys,
    Just created a workflow to copy some files from one location to another.
    Second thing I want to do is run a shell-script to set some file permissions recursively, some for the folders, the other for the files.
    I figured I could do the following:
    cd /IntoAFolder
    find . -type d -exec chmod 770 {} \;
    Unfortunately, this seems to be needed to be done as a sudo'er and thus requires the user's password.
    So the question is, how do I get that password and hand it to the shell script or is there another way of doing this?

    What I want to do is recursively chmod the subfolders and files of a "root"-folder.
    The way I know to do so is:
    cd /root-folder
    find . -type d -exec chmod 755 {} \;
    That will chmod all subfolders from the root-folder to 755.
    Next i want
    find . -type f -exec chmod 644 {} \;
    That will chmod all subfiles fromn the root-folder to 644
    Unfortunately, find gives me a permission denied when I run this command from the command-line. When I just manualy chmod everything that works fine but is a bit to much work when it comes down to a tree of 5 subfolders and 120 files.
    Waht basically hapens:
    The user selects a bunch of folders.
    Then they are copied to /Applications/RCT3.localised/Data/Styles/Themed
    and then I need to chmod them just to be sure, as sometimes stuff break along the way if you don't

  • Writing a shell script to move files

    Hello,
    I'm trying to write a shell script that will move files from one directory to another at a time specified by me. I've got a similar script attached to an Automator action, which is triggered nightly by iCal.
    Of course, this one simply deletes files that are older than a day in a couple of locations. I'd like to have another that MOVES files and folders from one location to another. So far, I've come up with this:
    find /Volumes/Location/01/* -type d -or -type f -mtime +7 -exec mv -f /Volumes/Location/01/* /Volumes/Location/02/ ;
    Which just about works, but it actually seems to be moving all the files that are LESS than a week old. Any and all suggestions are appreciated, as I'm a total n00b here.

    find /Volumes/Location/01/*
    -type d -or -type f -mtime +7
    -exec mv -f /Volumes/Location/01/* /Volumes/Location/02/ ;
    Which just about works, but it actually seems to be moving all the files
    that are LESS than a week old. Any and all suggestions are appreciated,
    as I'm a total n00b here.
    your -exec is not selecting the files or directories found by the 'find' command.
    It is moving everything in /Volumes/Location/01/*
    Looking at "man find", I think you want your -exec to be
    -exec /Volumes/Location/01/{} /Volumes/Location/02/ ;
    As red_menace has pointed out, you have to change your -type options
    so that you select directories or files.
    You may also want to include -prune so that you do not decend
    into subdirectories.
    While the following is untested, I might write the command like this:
    find /Volumes/Location/01/*
    -prune -mtime +7
    ( -type d -or -type f )
    -exec mv -f /Volumes/Location/01/{} /Volumes/Location/02/ ;

  • Shell Scripting to replace file type

    Hey all,
    I'm having some trouble with a shell script. I'm trying to run a script that will look through all the folders in a given directory for a certain type of file (.data) and then will run a getfileinfo -t on the .data file and, if the type is "" (empty), replace it with a given string.
    So far I can get the command to look through directories and I can get it to echo the getfileinfo -t, but I can't put the result of the command into a variable so I can check to see if it meets the "" condition. Any help would be greatly appreciated.
    Also, I am doing this in CSH, but I am no opposed to doing it another way, just so long as it works.

    Hi JohnSka7,
       I really like Niel's solution but it can be done in a script without AppleScript if you have Apple's Developer Tools installed. I don't do csh so I'll give it to you in bash and leave it as an exercise to translate:
    #!/bin/bash
    oldIFS=$IFS
    IFS=$'\n'
    for FILE in $( find "$1" -type f -name "*.data" ); do
       IFS=$oldIFS
       if [ \"\" = $( /Developer/Tools/GetFileInfo -t "$FILE" ) ]; then
          /Developer/Tools/SetFile -t "XXXX" "$FILE"
       fi
    done
    This temporarily sets the Input Field Separator, IFS, to a newline so that the snippet can handle filenames containing spaces. It assumes that the first argument to the script is the directory to be searched. Of course you should change "XXXX" to the type code you want and you can arrange for that to be specified in another argument. If you copy-and-paste this into a script, be sure to replace the non-breaking spaces I've used for indention with real spaces.
    Gary
    ~~~~
       Maslow's Maxim:
          If the only tool you have is a hammer, you treat
          everything like a nail.

  • Shell script, automator and file permissions

    We have an environment where, that when a user creates a folder on a network vol, it is owned by them and no one else has access to it. They then place a folder structure from there local HD into that folder they just created on the server. You would think a simple get info window with the user changing the permissions to include all would actually change all the file permissions in the enclosed folder, but it doesn't. I have a simple script written in automator using /bin/bash that is supposed to change the permissions in every folder and file to rw for all (user, group and everyone). It doesn't seem to be working correctly all the time for a few users.
    for f in "$@"
    do
    chmod -R 777 "$f"
    done
    I have tried this as well
    for f in "$@"
    do
    chmod -R a+rw "$f"
    done
    But that should be pretty much the same thing.
    Something i have noticed is the users with the most problem are running 10.4.11, while the script was written in 10.5. Also the users that are having the problem dont seem to have the same get info window as the rest of the 10.4.11 users, it very closely resembles 10.5, with some minor differences. It seems they are missing the groups or something. This might be more or less than an issue than I realize.
    http://picasaweb.google.com/tiemmothi/UserPermissions?feat=directlink
    the 10.4 window in question is "the offender" and
    "Mine" is 10.5

    *Access Control List* entries are in addition to the regular POSIX permissions. They are not required, but add finer levels of access control. Setting the regular permissions to read/write for everyone should work unless there are ACL entries which allow additional access - you can see ACL entries and extended attributes with/bin/ls -le@d /path/to/some/folder
    An inherited ACL entry to allow everyone read/write access would look something likechmod -R +a "everyone allow list,addfile,search,delete,add_subdirectory,delete_child,readattr,writeattr,chown,file_inherit,directoryinherit" /path/to/some/folderA users */Public/Drop Box* folder has similar entries.

  • Shell script to determine file width, height, resolution cs5 js

    I’ve been using a Script by Michael L Hale (that utilizes »xmp.getProperty« and Bridge’s »core.quickMetadata«) to determine files’s dimension and resolution without having to open or place them.
    Unfortunately it fails with some files (non-Photoshop generated bitmaps, it seems).
    (Pdfs I treat differently altogether to avoid the trouble of determining pdf-page counts and potential problems with pdfs containing differently sized pages.)
    Do any of you know if and how one can access files’ width, height, resolution with »app.system« in CS5?
    I may have come across it before, but can’t locate such a thread currently.
    Thanks for any input.

    These are 2 options that you could use if you wanted to dump all the info to text file then parse in JS. You could see if either of these contain the data that you are after?
    #target bridge
    var foo = File('~/Desktop/SomeFile.tif');
    getAllXMLSIPS(foo);
    //getMetaDataMDLS(foo)
    function getAllXMLSIPS(f) {
         if (f instanceof File && f.exists) {
              var shellString = "sips --getProperty allxml ";
              shellString += f.fsName;
              shellString += ' > ~/Documents/StdOut.txt';
              app.system(shellString);
    function getMetaDataMDLS(f) {
         if (f instanceof File && f.exists) {
              var shellString = "/usr/bin/mdls ";
              shellString += f.fsName;
              shellString += ' > ~/Documents/StdOut.txt';
              app.system(shellString);

  • Passing shell script variable to sql file by reference (bind variable)

    Hi All,
    I need to import around 50 files every 15 minutes into my target table.
    I am using shell script and call procedure to do transform.
    I used crontab to do this automate task.
    Here is my shell script and sql file:
    shell script:
    #!/bin/sh
    export ORACLE_HOME=/u01/app/oracle/product/9.2.0.4.0
    export PATH=$ORACLE_HOME/bin
    find /path_rawfile/rawfile -iname raw\*.in > myfile.lst
    nfile=1
    while [ true ]
    do
    read iFile #read a line
    if [ $? -ne 0 ] #Break if EOF
    then
    break
    fi
    #$PATH/sqlplus -s /NOLOG @load_raw.sql $iFile
    #/bin/mv -f $iFile /path_rawfile/rawfile/done/
    done < myfile.lst
    sql file:
    connect test/test@evn1
    set serveroutput on
    variable filename varchar2(50)
    begin
    :filename := '&1';
    exec my_tranform(:filename);
    dbms_output.put_line(:filename);
    end;
    exit;
    Even I used bind variable pass to procedure my_transform...
    But when i query in sys.v_$sqlarea, the :filename:='&1' still hard parse to sqlarea.
    One filename one statement and keep increasing ..
    Could everyone help me to change it to bind varialbe(soft parse)?
    I would like to incresae my database performance.
    Thanks in advance.
    Cheer
    Message was edited by:
    lux

    It is the procedure.
    It's my fault.
    Here is my SQL file again:
    conn test/test@evn1
    variable filename varchar2(500);
    exec :filename:='&1';
    exec my_transform(:filename);
    exit;
    I call this sql file from shell script and call in loop due to i need to load all file one time.
    Once i use <<EOF it raise error that's why when I deleted it.
    Anyway, what I need to do here is to use bind variable (soft parse).
    Since I need to load around 50 files every 15 minutes.
    exec :filename:='&1'; this statmet have found hard parse in v_$sqlarea.
    I would like to change this to bind varialbe.
    Thanks again for your help.

  • Displaying an alert (Applescript or otherwise) from shell script?

    I have a point in a shell script where I'd like to put up an alert dialogue on a particular error condition. The script runs in the background and doesn't have a terminal window. I tried writing a little applescript that uses the applescript alert command and call it using osascript from my shell script, but it doesn't work. If I enter "osascript ~/myscript.scpt" in a terminal window, I get the error message "/Users/Ted/myscript.scpt: execution error:No user interaction allowed. (-1713)" (If I run myscript.scpt from the script editor it does what I want it to do.) Any ideas? I suppose I could have my shell script create a file in some folder and have my applescript be triggered as a folder action, but that seems pretty roundabout!

    Thanks -- I apologize for not doing a more thorough search! Yes, that comes very close to addressing my need, but I have run into one difficulty. If I run my shell script from the terminal (pasting it in) everything works fine. If I run it as a packaged app (with Platypus) everything works like it's supposed to, except that the alert applescript (it's just a one line script) briefly flashes the alert dialogue when it's supposed to and then dies, rather than waiting 10 seconds or until I click OK. I'll have to experiment and see if I can tell what's going on.

  • 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

  • Modify shell script to work with other folders

    i am trying to modify a shell script that sorts files in a course folder into sub folders by month. I have a shell script that works, but when i try to modify it for another course folder it quits working. can someone let me know what i am doing wrong?
    the working shell script:
    do shell script "
    for f in \"$HOME/Desktop/DWI Annual Report/\"*
    do if [ ! -d \"$f\" ]; then
    x=\"${f%%.*}\"
    i=$((${#x}-3))
    if [ -d \"$HOME/Desktop/DWI monthly/${f:$i:3}\" ]; then
    mv \"$f\" \"$HOME/Desktop/DWI monthly/${f:$i:3}\"
    fi
    fi
    done"
    the nonworking modified script:
    do shell script "
    for f in \"$HOME/Desktop/DOEP Annual Report/\"*
    do
        if [ ! -d \"$f\" ]; then
            x=\"${f%%.*}\"
            i=$((${#x}-3))
            if [  -d \"$HOME/Desktop/DOEP monthly/${f:$i:3}\" ]; then
                mv \"$f\" \"$HOME/Desktop/DOEP monthly/${f:$i:3}\"
            fi
        fi
    done"

    ok here is the applescript that works.
    property total_student : 1
    tell application "Finder"
      set master_path to alias "Users:macbook:Desktop:DWI Annual Report:Annual Report.xlsx"
      set filesWithDWI to get every file of folder ((path to desktop folder) & "DWI Annual Report" as string) whose name contains "DWI"
      repeat with f in filesWithDWI
      my transfer_data(f, master_path)
      end repeat
    end tell
    on transfer_data(child_path, master_path)
      tell application "Microsoft Excel"
      set child_book to (open workbook workbook file name (child_path as string))
      set child_doc to worksheet 1 of child_book
      set master to worksheet "sheet 1" of (open workbook workbook file name (master_path as string))
      set num to 15 --All lists start at index 12 or later, I'm putting 10 to be safe
      set students to {}
      tell child_doc --grab values from child document
      repeat until (value of cell (("A" & num) as string)) is 1
      set num to num + 1
      end repeat
      repeat until (value of cell (("B" & num) as string)) is ""
      set end of students to {namevalue of cell (("B" & num) as string)), driver_idvalue of cell (("C" & num) as string)), DOBvalue of cell (("D" & num) as string)), Ref_Recvalue of cell (("I" & num) as string)), pre_testvalue of cell (("J" & num) as string)), post_testvalue of cell (("K" & num) as string)), cert_idvalue of cell (("L" & num) as string))}
    set num to num + 1
      end repeat
      set startdate to range "C7"
      set classlocation to range "C11"
      set instructor to range "H7"
      end tell
      tell master
      set num to 7
      log (value of cell (("B" & num) as string))
      repeat until (value of cell (("B" & num) as string)) is ""
      set num to num + 1
      end repeat
      repeat with student in students
      set value of cell (("A" & num) as string) to total_student
      set value of cell (("B" & num) as string) to name of student
      set value of cell (("C" & num) as string) to driver_id of student
      set value of cell (("D" & num) as string) to DOB of student
      set value of cell (("H" & num) as string) to pre_test of student
      set value of cell (("I" & num) as string) to post_test of student
      set value of cell (("J" & num) as string) to cert_id of student
      set value of cell (("f" & num) as string) to startdate
      set value of cell (("E" & num) as string) to classlocation
      set value of cell (("G" & num) as string) to instructor
      set value of cell (("K" & num) as string) to Ref_Rec of student
      set num to num + 1
      set total_student to total_student + 1
      end repeat
      end tell
      save child_book
      close child_book
      save active workbook in master_path
      close active workbook
      end tell
    end transfer_data
    do shell script "
    for f in \"$HOME/Desktop/DWI Annual Report/\"*
    do
        if [ ! -d \"$f\" ]; then
            x=\"${f%%.*}\"
            i=$((${#x}-3))
            if [  -d \"$HOME/Desktop/DWI monthly/${f:$i:3}\" ]; then
                mv \"$f\" \"$HOME/Desktop/DWI monthly/${f:$i:3}\"
            fi
        fi
    done"
    It takes the class rosters and copies the information from the class roster to the annual report and then moves the file to the monthly  folder and files it in the appropriate months folder based on the last three letters of the file name.

  • Inconsistencies with  "grep" in do shell script

    I've looked at this every way I can think of, but I've been unable to figure out why one script works and the other doesn't. Ideas would be appreciated.
    --SCRIPT 1 (works)
    set T to "one cat
    two lions
    one dog"
    do shell script "echo " & quoted form of T & " | grep one"
    temp.file for SCRIPT 2 is:
    one cat
    two lions
    one dog
    --SCRIPT 2 (grep doesn't work)
    set T to do shell script "cat ~/temp.file"
    do shell script "echo " & quoted form of T & " | grep one"
    2.7G5 AND OTHERS   Mac OS X (10.4.6)  

    (*
    Confirmation that the output of the cat command is being interpreted as one line is gained by using sed in place of grep. If, with sed, the global form of the command isn't used, then only the first "one" is changed, whereas, if the /g form is used, then both instances of "one" are changed:
    --SCRIPT 1 (works)
    set T to "one cat
    two lions
    one dog"
    do shell script "echo " & quoted form of T & " | sed 's/one/three/'"
    --SCRIPT 2 (changes only first instance of "one", implying single line)
    set T to do shell script "cat ~/temp.file"
    do shell script "echo " & quoted form of T & " | sed 's/one/three/'"
    --SCRIPT 2 (revised to include g)
    set T to do shell script "cat ~/temp.file"
    do shell script "echo " & quoted form of T & " | sed 's/one/three/g'"
    --Of course, if grep also sees only one line, its output is correct. But this whole analysis is confused (or enlightened?) by doing this:
    set T to do shell script "cat -n ~/temp.file"
    or set T to do shell script "cat -v ~/temp.file"
    both of which seem to show the output of cat as three lines.
    In the real world, the content of temp.file is complex and multiline so somehow I need to straighten things out at the cat command if possible.

  • Shell Script- To FTP the latest file with the date stamp

    I have a Solaris 10 based system, where it generate some application files (multiple) in XML format and the file name comprises of the current date.
    File Format is as follows;
    CX-FIL-20070624000000-2-8452536d-000133.xml
    Where 20070624 repesents the curent date of the file
    I want to FTP these files to another server (Solaris 10 based Sun Machine) by comparing the file name with the current date.
    Please let me know how I can do this by using a shell script.

    Assuming you want to ftp the files with today's datestamp, you could match the files you want like so:
    CX-FIL-`/bin/date +"%Y%m%d"`*
    Use that in your script to generate the file list to be transferred...
    -Rob

Maybe you are looking for