1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2006
    Rep Power

    UNIX Script Help


    I am new to UNIX shell scripting but I am willing to learn :-)

    I have to use the C shell....

    I have to write a script that should do the following:
    - Open an input file and read it line by line.
    - For each line read, I have to search for a certain pattern. If it was found then I have to ignore the following two lines and read the following line and store it for further processing. Otherwise, I will just read the following line.
    - After the previously mentioned hit is found and the following desired line is read, I have to write one line to another output file that is composed of some texts from the previously read files.
    - I have to do that till the end of the file.
    - I have to automate the process (this is not important and can be delayed).

    Please help me.

    Thanks in advance.

    Example of the input file:


    Cont BXX1 2006-06-03 14:49:54


    <HIST> BXX1 MCMU-0 TRANSM 2006-06-03 10:26:56.75
    ** ALARM ........ RRM_BX
    81d 2d 00 96d 11d 0d

    <HIST> BXX1 MCMU-0 TRANSM 2006-06-03 10:28:40.73
    .. CANCEL ........ RRM_BX
    81d 2d 00 96d 11d 0d

    Example of the output file:
    exemmlm -n BXX1 -c "EX:CMDx=81,CMDy=2,CMDz=00:L;"
    exemmlm -n BXX1 -c "EX:CMDx=81,CMDy=2,CMDz=00:L;"
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    Yuk! It may not sound obvious but you may want to take a look at awk.
    With that you can process a file, setting up a pattern match which, when found will read next 2 lines (and ignore them!), plus you should be able to save previous information in variables to help with the output.
    Looking at things, it appears your string being looked for is BXX1, so something like:
    awk '/<HIST> BXX1/ {getline; getline; x=$1; y=$2; z=$3; printf("exemmlm -n BXX1 -c \"EX:CMDx=%s,CMDy=%s,CMDz=%s:L;\"\n",x,y,z)}'
    That is just off the top of myhead and you would need to arrange for the alphas to be dropped from the end of the "81d" field to leave you with just 81. Also, you'd need to redirect output to your file.
    The awk man pages should help you out with that.

IMN logo majestic logo threadwatch logo seochat tools logo