Print Line as per the dependent sequence in shell script.


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Print Line as per the dependent sequence in shell script.
# 1  
Old 06-07-2019
Print Line as per the dependent sequence in shell script.

Hi i have a file like this as shown below:

Code:
DA        PROCESS_ID IDENTIFIER          DA_FILE                        STATUS          WAITING_FOR                   SCOPED_DEPENDENT

1836       21000    01052019             BH90P.TEMP.DA1836.FTP             W            NULL                                    S

1836       22000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/21000                              S

1836       23000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/22000                              S

1836       24000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/23000                              S

1836       25000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/24000;1801/24000;2248/24000        S

1836       26000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/25000                              S

1836       27000    01052019             BH90P.TEMP.DA1836.FTP             W            1836/26000                              S

1836       ETL31    01052019             BH90P.TEMP.DA1836.FTP             W            1836/27000                              S

1836       ETL32    01052019             BH90P.TEMP.DA1836.FTP             W            1836/ETL31                              S

1836       ETL33    01052019             BH90P.TEMP.DA1836.FTP             W            1836/ETL32                              S

2120       24000    01052019             BH90P.*                           W            1801/ETL33;1836/ETL33;2248/ETL33        D

2120       25000    01052019             BH90P.*                           W            2120/24000                              D

2207       24000    01052019             BH90P.NORDEASE.DA2207.FTP         W            2120/25000                              D

2207       25000    01052019             BH90P.NORDEASE.DA2207.FTP         W            2207/24000;2208/24000;2209/24000        D

2208       24000    01052019             BH90P.NORDEASE.DA2208.FTP         W            2120/25000                              D

2208       25000    01052019             BH90P.NORDEASE.DA2208.FTP         W            2208/24000                              D

2209       24000    01052019             BH90P.NORDEASE.DA2209.FTP         W            2120/25000                              D

2209       25000    01052019             BH90P.NORDEASE.DA2209.FTP         W            2209/24000                              D

2248       24000    01052019             BH90P.NORDEAFI.DA2248.FTP         W            1836/24000                              D

2248       25000    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/24000                              D

2248       26000    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/25000                              D

2248       27000    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/26000                              D

2248       ETL31    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/27000                              D

2248       ETL32    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/ETL31                              D

2248       ETL33    01052019             BH90P.NORDEAFI.DA2248.FTP         W            2248/ETL32                              D

1577       ETL31    01052019             BH90P.NORDEAFI.DA1577.FTP         W            1592/27000;1596/27000;1836/27000        D

1577       ETL32    01052019             BH90P.NORDEAFI.DA1577.FTP         W            1577/ETL31                              D

1577       ETL33    01052019             BH90P.NORDEAFI.DA1577.FTP         W            1577/ETL32                              D

1588       ETL31    01052019             BH90P.NORDEAFI.DA1588.FTP         W            1592/27000;1596/27000;1836/27000        D

1588       ETL32    01052019             BH90P.NORDEAFI.DA1588.FTP         W            1588/ETL31                              D

1588       ETL33    01052019             BH90P.NORDEAFI.DA1588.FTP         W            1588/ETL32                              D

1590       24000    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1836/23000                              D

1590       25000    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/24000                              D

1590       26000    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/25000                              D

1590       27000    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/26000                              D

1590       ETL31    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/27000                              D

1590       ETL32    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/ETL31                              D

1590       ETL33    01052019             BH90P.NORDEAFI.DA1590.FTP         W            1590/ETL32                              D

1592       24000    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1836/23000                              D

1592       25000    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/24000                              D

1592       26000    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/25000                              D

1592       27000    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/26000                              D

1592       ETL31    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/27000                              D

1592       ETL32    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/ETL31                              D

1592       ETL33    01052019             BH90P.NORDEAFI.DA1592.FTP         W            1592/ETL32                              D

1596       24000    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1836/23000                              D

1596       25000    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/24000                              D

1596       26000    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/25000                              D

1596       27000    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/26000                              D

1596       ETL31    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/27000                              D

1596       ETL32    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/ETL31                              D

1596       ETL33    01052019             BH90P.NORDEAFI.DA1596.FTP         W            1596/ETL32                              D

1598       24000    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1836/23000                              D

1598       25000    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/24000                              D

1598       26000    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/25000                              D

1598       27000    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/26000                              D

1598       ETL31    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/27000                              D

1598       ETL32    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/ETL31                              D

1598       ETL33    01052019             BH90P.NORDEAFI.DA1598.FTP         W            1598/ETL32                              D

1801       24000    01052019             BH90P.NORDEASE.DA1801.FTP         W            1836/24000                              D

1801       25000    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/24000                              D

1801       26000    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/25000                              D

1801       27000    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/26000                              D

1801       ETL31    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/27000                              D

1801       ETL32    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/ETL31                              D

1801       ETL33    01052019             BH90P.NORDEASE.DA1801.FTP         W            1801/ETL32                              D

In this file Column 6 contains dependencies values , i want to read file line by line and Print each line if its dependencies is already printed.

for example if dependency i s then we can print line no 1 having PID - 21000 , similarly of PID-24000 if Dependency 1836/23000 is printed then only it can proceed to print.

How can i achieve the same using shell script because there are few cases where multiple dependecies are available like for PID-25000
1836/24000;1801/24000;2248/24000

Can any one help me with shell script achieve the same.

Moderator's Comments:
Mod Comment Please wrap your samples/codes into CODE TAGS as per forum rules.

Last edited by RavinderSingh13; 06-07-2019 at 09:23 AM..
# 2  
Old 06-07-2019
More guessing than reading / understanding / knowing your spec, I came up with

Code:
awk '{D[$1,$2]++; for (n=split($6, T, ";"); n; n--) if (T[n] in D) print}' SUBSEP="/" file

. Works?
# 3  
Old 06-10-2019
Hi Rudic ,

Checked with your reply but its giving the same output .
Let me clarify once more,
I want to arrange jobs in sequence , as we can see in first line if Waiting for Value in Null for "1836 21000" then it comes in number 1 in sequence for execution.
similarly for second line Waiting for Value is "1836/21000" so "1836 22000" comes in second number in sequence for execution.
:
:
:
For line "1836 25000 01052019 BH90P.TEMP.DA1836.FTP W 1836/24000;1801/24000;2248/24000"
Waiting for Value is "1836/24000;1801/24000;2248/24000" so we know the "1836 24000" is already in sequence before this job but "1801 24000" and "2248 24000" somewhere later in the so its necessary put those before this in sequence and also check their waiting for value as well ...

Its like a Once job having multiple dependency but i want to arrange them in sequence using shell script so that i can execute it using my job scheduler.
# 4  
Old 06-10-2019
Quote:
Originally Posted by krishnaswarnkar
Hi Rudic ,

Checked with your reply but its giving the same output .
No, it suppresses lines that don't have a dependency met.
Quote:
...
For line "1836 25000 01052019 BH90P.TEMP.DA1836.FTP W 1836/24000;1801/24000;2248/24000"
Waiting for Value is "1836/24000;1801/24000;2248/24000" so we know the "1836 24000" is already in sequence before this job but "1801 24000" and "2248 24000" somewhere later in the so its necessary put those before this in sequence and also check their waiting for value as well ...
Do you mean you need ALL dependencies met? Why not say so? What would the desired output look like (small but representative sample)?


Quote:
Its like a Once job having multiple dependency but i want to arrange them in sequence ...
What do you mean?
# 5  
Old 06-10-2019
Thanks Rudic ,
Added a sequence column , Need to arrange in the sequence numbers as mentioned in the last field so that no Job goes on wait if arranged in this manner.

DA PROCESS_ID IDENTIFIER DA_FILE STATUS WAITING_FOR SCOPED_DEPENDENT SEQUENCE
1836 21000 01052019 BH90P.TEMP.DA1836.FTP W NULL S 1
1836 22000 01052019 BH90P.TEMP.DA1836.FTP W 1836/21000 S 2
1836 23000 01052019 BH90P.TEMP.DA1836.FTP W 1836/22000 S 3
1836 24000 01052019 BH90P.TEMP.DA1836.FTP W 1836/23000 S 4
1836 25000 01052019 BH90P.TEMP.DA1836.FTP W 1836/24000;1801/24000;2248/24000 S 7
1836 26000 01052019 BH90P.TEMP.DA1836.FTP W 1836/25000 S 8
1836 27000 01052019 BH90P.TEMP.DA1836.FTP W 1836/26000 S 9
1836 ETL31 01052019 BH90P.TEMP.DA1836.FTP W 1836/27000 S 10
1836 ETL32 01052019 BH90P.TEMP.DA1836.FTP W 1836/ETL31 S 11
1836 ETL33 01052019 BH90P.TEMP.DA1836.FTP W 1836/ETL32 S 12
2120 24000 01052019 BH90P.* W 1801/ETL33;1836/ETL33;2248/ETL33 D 26
2120 25000 01052019 BH90P.* W 2120/24000 D 27
2207 24000 01052019 BH90P.NORDEASE.DA2207.FTP W 2120/25000 D 28
2207 25000 01052019 BH90P.NORDEASE.DA2207.FTP W 2207/24000;2208/24000;2209/24000 D 31
2208 24000 01052019 BH90P.NORDEASE.DA2208.FTP W 2120/25000 D 29
2208 25000 01052019 BH90P.NORDEASE.DA2208.FTP W 2208/24000 D 32
2209 24000 01052019 BH90P.NORDEASE.DA2209.FTP W 2120/25000 D 30
2209 25000 01052019 BH90P.NORDEASE.DA2209.FTP W 2209/24000 D 33
2248 24000 01052019 BH90P.NORDEAFI.DA2248.FTP W 1836/24000 D 6
2248 25000 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/24000 D 19
2248 26000 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/25000 D 20
2248 27000 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/26000 D 21
2248 ETL31 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/27000 D 23
2248 ETL32 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/ETL31 D 24
2248 ETL33 01052019 BH90P.NORDEAFI.DA2248.FTP W 2248/ETL32 D 25
1577 ETL31 01052019 BH90P.NORDEAFI.DA1577.FTP W 1592/27000;1596/27000;1836/27000 D 42
1577 ETL32 01052019 BH90P.NORDEAFI.DA1577.FTP W 1577/ETL31 D 43
1577 ETL33 01052019 BH90P.NORDEAFI.DA1577.FTP W 1577/ETL32 D 44
1588 ETL31 01052019 BH90P.NORDEAFI.DA1588.FTP W 1592/27000;1596/27000;1836/27000 D 45
1588 ETL32 01052019 BH90P.NORDEAFI.DA1588.FTP W 1588/ETL31 D 46
1588 ETL33 01052019 BH90P.NORDEAFI.DA1588.FTP W 1588/ETL32 D 47
1590 24000 01052019 BH90P.NORDEAFI.DA1590.FTP W 1836/23000 D 48
1590 25000 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/24000 D 49
1590 26000 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/25000 D 50
1590 27000 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/26000 D 51
1590 ETL31 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/27000 D 52
1590 ETL32 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/ETL31 D 53
1590 ETL33 01052019 BH90P.NORDEAFI.DA1590.FTP W 1590/ETL32 D 54
1592 24000 01052019 BH90P.NORDEAFI.DA1592.FTP W 1836/23000 D 34
1592 25000 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/24000 D 35
1592 26000 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/25000 D 36
1592 27000 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/26000 D 37
1592 ETL31 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/27000 D 55
1592 ETL32 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/ETL31 D 56
1592 ETL33 01052019 BH90P.NORDEAFI.DA1592.FTP W 1592/ETL32 D 57
1596 24000 01052019 BH90P.NORDEAFI.DA1596.FTP W 1836/23000 D 38
1596 25000 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/24000 D 39
1596 26000 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/25000 D 40
1596 27000 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/26000 D 41
1596 ETL31 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/27000 D 58
1596 ETL32 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/ETL31 D 59
1596 ETL33 01052019 BH90P.NORDEAFI.DA1596.FTP W 1596/ETL32 D 60
1598 24000 01052019 BH90P.NORDEAFI.DA1598.FTP W 1836/23000 D 61
1598 25000 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/24000 D 62
1598 26000 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/25000 D 63
1598 27000 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/26000 D 64
1598 ETL31 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/27000 D 65
1598 ETL32 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/ETL31 D 66
1598 ETL33 01052019 BH90P.NORDEAFI.DA1598.FTP W 1598/ETL32 D 67
1801 24000 01052019 BH90P.NORDEASE.DA1801.FTP W 1836/24000 D 5
1801 25000 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/24000 D 13
1801 26000 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/25000 D 14
1801 27000 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/26000 D 15
1801 ETL31 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/27000 D 16
1801 ETL32 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/ETL31 D 17
1801 ETL33 01052019 BH90P.NORDEASE.DA1801.FTP W 1801/ETL32 D 18

# 6  
Old 06-10-2019
Just to quote RudiC:
Quote:
Originally Posted by RudiC
What would the desired output look like (small but representative sample)?
A desired output would be helpful as well....
Also, you've been asked to start using code tags when posting code/data sample...
This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 06-11-2019
Hi Rudic,

Hope you got the desired output , basically i need a field which shows the number in which the Jobs can be arranged.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to run multiple jobs and it's dependent jobs

I have multiple jobs and each job dependent on other job. Each Job generates a log and If job completed successfully log file end's with JOB ENDED SUCCESSFULLY message and if it failed then it will end with JOB ENDED with FAILURE. I need an help how to start. Attaching the JOB dependency... (3 Replies)
Discussion started by: santoshkumarkal
3 Replies

2. Shell Programming and Scripting

Will shell script executes in sequence

I have a shell script scheduled in cron job to run at every 1 minute which transfers files to remote machine and then move the files to backup folder. cd /u01/app/ftp_tmp sftp user@hostname <<-EOF cd /home/user/ftp mput * bye EOF mv /u01/app/ftp_tmp/* /u01/app/ftp_bkp Now the problem is... (6 Replies)
Discussion started by: Bhavi
6 Replies

3. Shell Programming and Scripting

Print combinations of alphabets in a sequence

Hi Friends, I have a series of alphabets like this AGCAA The values inside the square brace indicate that either of them can be present at that position. And those ones without a brace, means that they are the only ones that could be printed at that location. Now, I would like to know... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

4. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

5. UNIX for Advanced & Expert Users

Checking missing data's sequence (shell script | UNIX command)

Dear All members, i have some trouble here, i want to ask your help. The case is: I have some data, it's like: -ABCD1234 -ABCD1235 -ABCD1237 -BCDE1111 -BCDE1112 -BCDE1114 there is some missing data's sequence (the format is: ABCD = name 1234 = sequence). I want to print the... (2 Replies)
Discussion started by: septian.tri
2 Replies

6. Shell Programming and Scripting

print out missing files in a sequence

Hello all, I have several directories with a sequence of files like this IM-0001-0001.dcm IM-0001-0002.dcm IM-0001-0003.dcm IM-0001-0004.dcm IM-0001-0005.dcm I would like to print out the name of the file that is missing. I currently have the following ineffecient way to do this... (4 Replies)
Discussion started by: avatar_007
4 Replies

7. UNIX for Advanced & Expert Users

Sequence number merged with hypen, shell script

Hello Folks, i have to write shell scripting for given expected output manner. in given input we have to write shell script in such a way that sequence no can b merged/link between start and end digit with hyphen "-" symbol and rest of digit separated by "," Eg : For Input "2 6 7 8 11 12... (9 Replies)
Discussion started by: panchalh
9 Replies

8. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

9. Shell Programming and Scripting

sed script - print the line number along with the line

Hi, I want to print the line number with the pattern of the line on a same line using multi-patterns in sed. But i don't know how to do it. For example, I have a file abc def ghi I want to print 1 abc 2 def 3 ghi I know how to write it one line code, but i don't know how to put... (11 Replies)
Discussion started by: ntpntp
11 Replies

10. Shell Programming and Scripting

awk/shell script to print each line to a file

Dear People, My query is: have a file, which looks likes this: 10 20 30 40 50 1 2 3 4 5 100 200 300 400 500 what i need is: "PRINT EACH LINE TO AN UNIQUE FILE" desired output: file 1 10 20 30 40 50 file 2 1 2 3 4 5 (3 Replies)
Discussion started by: saint2006
3 Replies
Login or Register to Ask a Question