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

Similar Messages

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

  • Reg: UNIX shell script at File Adapter

    Hi all,
    I am doing a File to file scenario and using command line arguments in Sending file adapter. I am using UNIX shell script ".sh" file for executing the command.
    I gave the following path at "Run OS command before message processing" parameter:
    /temp/xidelivery/send/FILOSC004_shell.sh
    and this file contains following code:
    <b>#!/user/bin/sh cp /temp/xidelivery/send/FILOSC004_in.txt /temp/xidelivery/send/FILOSC004_input_copy4.txt</b>
    I put the source file, FILOSC004_in.txt and shell script files at the respective paths.
    If I give "cp" command directly in command line it is working fine. But I could not execute this with shell script. Can any body give me the reason where I gone wrong.
    Regards,
    Pavani.

    Hi,
    can you try this,
    bash /temp/xidelivery/send/FILOSC004_shell.sh
    let me know.
    hey you can check the blog below to catch the OS errors,
    /people/michal.krawczyk2/blog/2005/08/17/xi-operation-system-command--error-catching
    Prasad Babu.
    Message was edited by:
            PrasadBabu Koribilli

  • How to read specific line in a file through UNIX shell script..

    Dear Friends,
    I have generated .ldt file under admin/import/US folder through FND_LOAD script for Download the responsibility.
    I registred Shell script (Host concurrent program) in Oracle apps. Now i want to read the file in speciific line which i was generated in admin/import/US folder through unix shell script. Please help me how to read specific line and the i want to replace that which i am going to read the specific line.
    Thanks in advance..
    Regards,
    Velu.

    Hi,
    Thanks for reply,
    My requirement i have to find the specific line in a file and find and replace needed word over there it's should happen programatically. i want to read specific line in a file Once complete find and replace the condition should exists. The loop will go to next file and read the same line in next file also do the same process upto how many files over there.i am doing through UNIX shell script. Please help me out to find the
    Your suggestion is highly appriciated.
    Thanks,
    Velu.

  • Can I call host file ( Unix Shell script ) from Oracle 10g trigger

    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    parag

    user12009546 wrote:
    Hi,
    I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
    thanks & regards
    paragIf you are in 10g, you can simple call shell script from DBMS_SCHEDULER:
    BEGIN
    DBMS_SCHEDULER.CREATE_JOB (
    job_name => 'TEST_SCRIPT',
    job_type => 'EXECUTABLE',
    job_action => 'PATH_OF_YOUR_SCRIPT',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=MINUTELY; INTERVAL=1',
    enabled => TRUE,
    comments => 'Shell script from Oracle'
    END;
    /

  • Need Help in creating Unix Shell Script for database

    Would be appreciable if some one can help in creating unix shell script for the Oracle DB 10,11g.
    Here is the condition which i want to implement.
    1. Create shell script to create the database with 10GB TB SPACE and 3 groups of redo log file(Each 300MB).
    2. Increase size of redolog file.
    3. Load sample schema.
    4. dump the schema.
    5. Create empty db (Script should check if db already exists and drop it in this case).
    6. Create backup using rman.
    7. restore backup which you have backed up.

    This isn't much of a "code-sharing" site but a "knowledge-sharing" site.  Code posted me may be from a questioner who has a problem / issue / error with his code.   But we don't generally see people writing entire scripts as responses to such questions as yours.  There may be other sites where you can get coding done "for free".
    What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
    But the expectation here is for you to write your own code.
    Hemant K Chitale

  • Schedule workbook using with Unix shell script

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

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

  • RFC_REMOTE_PIPE is Returning 1 alwasys and not able to execute Unix shell script

    Hello All,
    I am trying to execute a simple unix shell script from ABAP.
    What I did so far..
    1. created a test.sh file  with single command echo "Hello".
    2.  placed this file on application server /Usr/sap/test.sh
    3. executing ABAP program which as FM RFC_REMOTE_PIPE
    CODE:
    CALL FUNCTION 'RFC_REMOTE_PIPE'
       DESTINATION 'SERVER_EXEC'
    EXPORTING
       command  = lv_command
       read          = 'X'
    TABLES
       pipedate    =  lt_stdout
    EXCEPTIONS
    system_failure  = 1
    communication_failure = 2.
    if i populate lv_command  = echo "hello" it works fine
    if i give .sh file path in lv_command it is not working. it returns 1.
    Please help...
    I was searching SDN i found that rfcexec service should be enabled... how do i check that..
    i checked t code  \SMGW , i don't see any output...
    i checked FM GWY_READ_CONNECTED_SYSTEMS, i don't hsee anyting related to unix...
    Please suggest.

    I resolved the issue.
    It was issue with permission.
    Script file should have full permission ( Mode 777)..
    Thanks everyone.

  • Calling a report from unix shell script

    Hi,
    I had to call a report from unix shell script.
    May i know the procedure to accomplish this
    Thanks in Advance
    A.Gopal

    First you should not include the whole path to your report in the call ...
    Use like this:
    /ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
    In $ORACLE_HOME/bin/reports.sh:
    1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
    REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
    2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
    After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
    If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
    i.e.
    Change the following line:
    <!--trace traceOpts="trace_all"/-->
    to <trace traceOpts="trace_all"/>
    Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look.

  • Error while trying to execute a unix shell script from java program

    Hi
    I have written a program to execute a unix shell script in a remote machine. I am using J2ssh libraries to estabilish the session connection with the remote box.The program is successfully able to connect and authenticate with the box.
    The runtime .exec() is been implemented to execute the shell script.I have given below the code snippet.
    try {
         File file_location = new File("/usr/bin/");
         String file_location1 = "/opt/app/Hyperion/scripts/daily";
         String a_mib_name = "test.sh";
         String cmd[] = new String[] {"/usr/bin/bash", file_location1, a_mib_name};
         Runtime rtime = Runtime.getRuntime();
         Process p = rtime.exec(cmd, null, file_location);
    System.out.println( "Connected to the server1" );
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = br.readLine();
    while(line !=null)
    System.out.println(line);
    line = br.readLine();
    br.close();
    p.getErrorStream ().close ();
    p.getOutputStream().close();
    int retVal = p.waitFor();
    System.out.println("wait " + retVal);
    //session.executeCommand("ls");
    catch (IOException ex) {
    I get an error message
    Connected to the server
    java.io.IOException: Cannot run program "/usr/bin/bash" (in directory "\usr\bin"
    ): CreateProcess error=3, The system cannot find the path specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at SftpConnect.main(SftpConnect.java:143)
    Caused by: java.io.IOException: CreateProcess error=3, The system cannot find th
    e path specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    I am sure of the file path where the bash.sh and test.sh are located.
    Am i missing something? Any help would be greatly appreciated.
    Thanks
    Senthil

    Hi, I am using a simple program to connect to a RMI server and execute shell script. I use the Runtime.exec aommand to do the same.
    The script is sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul
    The script when run from the server, gives no errors. But when ran using rthe above method in java, gives errors as follows,
    Mycode:
    String command = "/bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    int exitVal = proc.exitValue();
    System.out.println("Process exitValue: " + exitVal);
    java.io.IOException: CreateProcess: /bin/sh /tmp/pub/alka/test.sh /tmp/pub/alka/abc/xyz/ul ul error=3
         at java.lang.ProcessImpl.create(Native Method)
         at java.lang.ProcessImpl.<init>(Unknown Source)
         at java.lang.ProcessImpl.start(Unknown Source)
         at java.lang.ProcessBuilder.start(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at DecryptTest.main(DecryptTest.java:18)
    Can anyone please help

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • Sending email attachments using unix shell script

    hi
    I want to send report generated my spooled file as attachment using unix shell script.
    Can somebody help me out ?
    many thanks

    thanks a tonn it worked.
    but i have another issue is it possible to add names in CC also ?
    Also here is my code which spools the output of SP to a txt file. the File name is generated dynamically.
    as shown below:
    I need to send this generated file as attachement.
    how do I do this? Here the shell script
    =========================================================
    #!/bin/sh
    ORA_USER=scott
    ORA_PWD=tiger
    #Get the input parameter
    if [ ! "$1" ]; then
    STR="NULL"
    else
    STR="'"$1"'"
    fi
    #echo "exec pkg1($STR);"
    #Connecting to oracle
    sqlplus -s <<EOF
    $ORA_USER/$[email protected]
    ---sql plus enviornment settings
    set linesize 160
    set pagesize 60
    set serveroutput on size 1000000 for wra
    set feedback off
    set termout off
    column dcol new_value mydate noprint
    select to_char(sysdate,'YYYYMMDDHH24MISS') dcol from dual;
    spool &mydate.report.txt
    exec pkg1($STR);
    spool off
    EOF
    exit
    =========================================================
    the file name will take sysdate as name so that every time a new file will be generated.
    this file I need to send as attachment.
    null

  • Please provide me unix shell script (export and import of database schema)

    please i am new in unix
    \please give me sample unix shell script (export and import of database schema)

    please i am new in unix
    \please give me sample unix shell script (export and import of database schema)Instead of providing you the readymade unix shell script for your requirement, I will give you the hints to prepare the same at your own.
    Create a file with .sh extension.
    # Specify and set all required Environment variables.
    ORACLE_HOME, PATH, NLS_LANG, etc.,
    # Use the export command with all clauses
    export scott/tiger@orcl file=scott.dmp log=scott_emp.log
    # Compress it.
    compress scott.dmp
    Refer any unix/linux documents for scripting basics.
    http://www.bijoos.com/ora7/oracle_unix.htm
    Regards,
    Sabdar Syed.

  • Comment in Unix shell script

    i have a doubt as to how to comment a line in a shell script as i have to do that in a config. file of Oracle 9i Application Server. Is it a "--" in a line. Please help.
    regards

    Try to use # as a comment in unix shell script.
    The config files in Oracle AS are xml based so the comment
    therefore is
    <!-- This is a comment -->
    Hope that helps.

  • Generate RMAN backup Script using unix shell script

    Hello,
    Could somebody give me a unix shell script that would generate RMAN script based on some user defined parameters in a config file.
    e.g.
    rman.conf
    CHANNELS=4
    USE_CATALOG=Y
    DEVICE='sbt_tabe'
    etc.,
    many thanks,
    kam

    You can actually encapsulate the RMAN commands inside the shell script.
    However if you really want to create a seperate RMAN script file, you can use the unix shell's "echo" command to write set variables to a file.
    Thus, for example,
    echo "rman target / catalog rman/rmanpassword@crcat" > RMAN_Script.rmn
    echo "backup database plus archivelog" >> RMAN_Script.rmn
    echo "backup archivelog all" >> RMAN_Script.rmn
    creates RMAN_Script.rmn with 3 commands.

Maybe you are looking for