The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 09:34 AM
Script Required Satadru Shell Programming and Scripting 1 05-08-2008 01:38 PM
Script required ntgobinath Shell Programming and Scripting 1 05-08-2008 12:35 PM
script required skyineyes Shell Programming and Scripting 13 06-27-2007 02:49 AM
Script help required! kev112 Shell Programming and Scripting 8 05-24-2005 05:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
Post A bit Complicate Script Required...

I have A very complex requirement

Dont know if it Possible by scripting....

I have do some parsing and replacement in COBOL Programs

It has Statements like

SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2
INPUT PROCEDURE INPUT-PROC

the Bold Ones are the Key Feilds..

If the Key feilds are in GROUP level then replace the Individulval variables Instead if Group Name...

The Lay out look like...

01 FS-REC1.
05 FS-KEY1.
10 FS-SOCT1 PIC 9(3) COMP-3.
10 FS-GER71 PIC 9(7) COMP-3.
05 FS-KEY2.
10 FS-TIER1 PIC 9(7) COMP-3.
05 AS-CLI1 PIC X(10).
05 BS-CLI1 PIC X(10).


Here FS-KEY1 and FS-KEY2 are Group feilds so
want the SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2

to become

SORT FSORT ASCENDING KEY FS-SOCT1
FS-GER71
FS-TIER1
INPUT PROCEDURE INPUT-PROC

The Key Feild can End with eithe INPUT or OUPUT or USING....

I have attached a sample Input file with Differenent Cases..

I would be great help if we can do this via a script..
Attached Files
File Type: txt inpfile.txt (1.6 KB, 15 views)
File Type: txt output.txt (1.8 KB, 14 views)
  #2 (permalink)  
Old 07-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960

Code:
#! /opt/third-party/bin/perl

my %justHash = ();

open(FILE, "<", "inp") || die "Unable to open file inp <$!>\n";

while (<FILE>) {
  chomp;
  if( /sort/i ) {
    s/.*(\d+)/\1/;
    print "SORT FSORT ASCENDING KEY ";
    my @sub_arr = split(/\|/, $justHash{$_});
    foreach(@sub_arr) {
      print "$_\n";
    }
  }
  print "$_\n";
  next if( /key(\d+)/i || /rec/i );
  if ( /FS-/ ) {
    s/PIC.*$//;
    s/^.* (\d\d)//;
    s/ //g;
    my $val = $_;
    s/.*(\d+)/\1/;
    $justHash{$_} = $justHash{$_} . "|" . $val;
  }
}

close(FILE);

exit 0

try this !
  #3 (permalink)  
Old 07-06-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
Dear Madhan

Its Fine for the Input i gave....(except that is put a number 1 2 3 after every replacement)

but And when i try this on the real COBOL Program(around 4000 lines) is jams the File...

there are some lines like

SELECT FSORT ASSIGN SORTWK1.
SELECT F60UH2 ASSIGN F60UH2E.
SELECT F60U4 ASSIGN F60U4S.


* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *


which i hope are corrupting the files....

Any word with SORT in it is doing some thing....

I have no clue of perl... I am very sorry ... not able to tell u what is the problem....

But to give u more information
the SORT FSORT ASCENDING KEY FS-SOCT1 is always constant...
then the key fields end with either INPUT or OUTPUT or USING...
and the KEY LAYouts.. group variables are always in 05 level ending with .

Last edited by pbsrinivas; 07-06-2007 at 08:03 AM..
  #4 (permalink)  
Old 07-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
Sorry, I couldn't generalize the script with your input.

But made sure its working for the input provided.

Will it be possible to provide a snippet of the input where the script is actually corrupting the files, so that I could revisit the script ?
  #5 (permalink)  
Old 07-06-2007
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
Quote:
Originally Posted by matrixmadhan View Post
Sorry, I couldn't generalize the script with your input.

But made sure its working for the input provided.

Will it be possible to provide a snippet of the input where the script is actually corrupting the files, so that I could revisit the script ?


If u could just add these inlines to the input file...

SELECT FSORT ASSIGN SORTWK1.

* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *


that should give u some clue..

I cant post the whole code online....

I will give u the code which is getting changed....



SELECT FSORT ASSIGN SORTWK1.
* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0.
88 FINFSORT VALUE 1.
77 CTR-FSORT-LUS PIC 9(9) COMP-3 VALUE ZERO.
77 CTR-FSORT-ECR PIC 9(9) VALUE ZERO.
* SORT PROCEDURE *
SORT FSORT ASCENDING KEY FS-KEY
IF SORT-RETURN NOT = ZERO
MOVE 'FSORT' TO FICH
ADD 1 TO CTR-FSORT-ECR.
ADD 1 TO CTR-FSORT-ECR
RETURN FSORT
MOVE 1 TO FIN-FSORT.
PERFORM LECT-FSORT
THRU LECT-FSORT-EXIT.
UNTIL FINF60UH2 AND FINFSORT.
PERFORM LECT-FSORT
THRU LECT-FSORT-EXIT.
LECT-FSORT.
MOVE 1 TO FIN-FSORT
PERFORM CUMUL-FSORT
THRU CUMUL-FSORT-EXIT
LECT-FSORT-EXIT.
* CUMUL-FSORT *
CUMUL-FSORT.
ADD 1 TO CTR-FSORT-LUS.
RETURN FSORT
CUMUL-FSORT-EXIT.



I if can just append these lines to input.... U shoule be able to see...
  #6 (permalink)  
Old 07-06-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
>cat inputfile

Code:
SELECT FSORT ASSIGN SORTWK1.

* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *

AAAAAA       01  FS-REC1.
BBBBBB           05  FS-KEY1.
                     10  FS-SOCT1               PIC 9(3) COMP-3.
D50180*              10  FS-GERA1               PIC 9(3) COMP-3.
D50180               10  FS-GER71               PIC 9(7) COMP-3.
                     10  FS-TIER1               PIC 9(7) COMP-3.
                 05  AS-CLI1                      PIC X(10).
                 05  BS-CLI1                      PIC X(10).



AAAAAA       01  FS-REC2.
BBBBBB           05  FS-KEY2.
                     10  FS-SOCT2              PIC 9(3) COMP-3.
D50180*              10  FS-GERA2               PIC 9(3) COMP-3.
                     10  FS-TIER2               PIC 9(7) COMP-3.
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).


AAAAAA       01  FS-REC3.
BBBBBB           05  FS-KEY3.
D50180*              10  FS-GERA3               PIC 9(3). 
                     10  FS-TIER3               PIC 9(7). 
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).

SORT FSORT ASCENDING KEY FS-KEY1
                         BS-CLI1
          INPUT PROCEDURE INPUT-PROC


SORT FSORT ASCENDING KEY FS-KEY2
                         BS-CLI2
           OUTPUT PROCEDURE OUTPUT-PROC.


SORT FSORT ASCENDING KEY FS-KEY3
            USING PROCEDURE OUTPUT-PROC.
            OUTPUT PROCEDURE OUTPUT-PROC.

And now execute the script I had provided and that doesn't really seem to affect the output anyway.

If you think that the script is screwing up the output, then just paste that of the input alone in CODE tags which would be quite easier to view and the output you are expecting out of the input !

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0