How to find the job outside the box?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find the job outside the box?
# 1  
Old 01-08-2015
How to find the job outside the box?

Hi gurus,

below file is job list, the records without s( in the begining is job name in the box, the records with s() is the job depends on them (some of them in the box, some of them not in the box). I need to use script to find the job name not in the box.
Code:
 
sname-pname-cprexa
sname-pname-cprexa-success-1
s(sname-pname-cprexhaa)
s(sname-pname-cprexloa)
sname-pname-cprexa-success-2
s(sname-pname-cprexmta)
s(sname-pname-cprexrga)
sname-pname-cprexa-phase-job
s(sname-pname-cprexa-success-2)
s(sname-pname-abcd-phase)

from above file, the inbox job is
Code:
 
sname-pname-cprexa
sname-pname-cprexa-phase-job
sname-pname-cprexa-success-1
sname-pname-cprexa-success-2

and the job not inbox is
Code:
 
sname-pname-cprexhaa
sname-pname-cprexloa
sname-pname-cprexmta
sname-pname-cprexrga
sname-pname-abcd-phase

I wrote a script to do this but it is a little bit compleated. I am wonder if there is any easy way to achive this task.

my script as below.
grep ^s( filename > file1
grep -v ^s > file2
then remove s( and ) with command sed 's/s(//' |sed 's/)//'
then compare these two file2 and file1 find outbox job.

any inputs are welcom.

thanks in advance.
# 2  
Old 01-08-2015
Hello ken6503,

Following may help you in same.
Code:
awk '/^s\(s/{A=1} !/^s\(s/{A=0} A{print $0 > "Found_jobs"} !A{print $0 > "NOT_found_jobs"}' Input_file
OR
awk '/^s\(s/{print $0 > "Found_jobs"} !/^s\(s/{print $0 > "NOT_found_jobs"}'  Input_file
OR
awk '/^s\(s.*\)$/{print $0 > "Found_jobs"} !/^s\(s.*\)/{print $0 > "NOT_found_jobs"}' Input_file
OR
awk '/^s\(s.*\)$/{print  > "Found_jobs";next} {print > "NOT_found_jobs"}' Input_file

It will create 2 files named Found_jobs and NOT_found_jobs as follows.
Code:
cat Found_jobs 
s(sname-pname-cprexhaa)
s(sname-pname-cprexloa)
s(sname-pname-cprexmta)
s(sname-pname-cprexrga)
s(sname-pname-cprexa-success-2)
s(sname-pname-abcd-phase)

cat NOT_found_jobs 
sname-pname-cprexa
sname-pname-cprexa-success-1
sname-pname-cprexa-success-2
sname-pname-cprexa-phase-job

Thanks,
R. Singh

Last edited by RavinderSingh13; 01-08-2015 at 01:34 PM.. Reason: Added one more solution
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 01-08-2015
Quote:
Originally Posted by RavinderSingh13
Hello ken6503,

Following may help you in same.
Code:
awk '/^s\(s/{A=1} !/^s\(s/{A=0} A{print $0 > "Found_jobs"} !A{print $0 > "NOT_found_jobs"}' Input_file
OR
awk '/^s\(s/{print $0 > "Found_jobs"} !/^s\(s/{print $0 > "NOT_found_jobs"}'  Input_file
OR
awk '/^s\(s.*\)$/{print $0 > "Found_jobs"} !/^s\(s.*\)/{print $0 > "NOT_found_jobs"}' Input_file
OR
awk '/^s\(s.*\)$/{print  > "Found_jobs";next} {print > "NOT_found_jobs"}' Input_file

It will create 2 files named Found_jobs and NOT_found_jobs as follows.
Code:
cat Found_jobs 
s(sname-pname-cprexhaa)
s(sname-pname-cprexloa)
s(sname-pname-cprexmta)
s(sname-pname-cprexrga)
s(sname-pname-cprexa-success-2)
s(sname-pname-abcd-phase)
 
cat NOT_found_jobs 
sname-pname-cprexa
sname-pname-cprexa-success-1
sname-pname-cprexa-success-2
sname-pname-cprexa-phase-job

Thanks,
R. Singh
Thanks Singh for your reply.

the ways you provied work fine.
my goal is to compare the found and not found job and list the jobs that is in found but not in not_found. in above case I want to get below out put

Code:
 
sname-pname-cprexhaa
sname-pname-cprexloa
sname-pname-cprexmta
sname-pname-cprexrga
sname-pname-abcd-phase

is it possible to achieve this within same command?

thanks in advance

Last edited by ken6503; 01-08-2015 at 04:33 PM..
# 4  
Old 01-08-2015
How about
Code:
awk     '$1=="s"        {sub (/\)/,"",$2)
                         OUT[$2]
                         next}
                        {IN[$1]}
          END           {for (C in OUT) if (!(C in IN)) print C}
        ' FS="(" file
sname-pname-cprexmta
sname-pname-abcd-phase
sname-pname-cprexloa
sname-pname-cprexrga
sname-pname-cprexhaa

This User Gave Thanks to RudiC For This Post:
# 5  
Old 01-08-2015
Quote:
Originally Posted by RudiC
How about
Code:
awk     '$1=="s"        {sub (/\)/,"",$2)
                         OUT[$2]
                         next}
                        {IN[$1]}
          END           {for (C in OUT) if (!(C in IN)) print C}
        ' FS="(" file
sname-pname-cprexmta
sname-pname-abcd-phase
sname-pname-cprexloa
sname-pname-cprexrga
sname-pname-cprexhaa

Thanks RudiC.

the code works perfectly.
# 6  
Old 01-09-2015
Quote:
Originally Posted by ken6503
Thanks Singh for your reply.

the ways you provied work fine.
my goal is to compare the found and not found job and list the jobs that is in found but not in not_found. in above case I want to get below out put

Code:
 
sname-pname-cprexhaa
sname-pname-cprexloa
sname-pname-cprexmta
sname-pname-cprexrga
sname-pname-abcd-phase

is it possible to achieve this within same command?
thanks in advance
Hello Ken6503,

Following may help you in same.
Code:
awk '/^s\(s/{sub(/^s\(/,X,$0);sub(/\)$/,Y,$0);A[$0]=$0;next} !/^s\(s/{B[$0]} END{for(j in B){W=B[j];for(W in A){delete A[j]}};for(u in A){print A}}' Input_file

Output will be as follows.
Code:
sname-pname-cprexhaa
sname-pname-abcd-phase
sname-pname-cprexrga
sname-pname-cprexloa
sname-pname-cprexmta

EDIT: Adding non oneliner command for same.
Code:
awk '/^s\(s/{
                sub(/^s\(/,X,$0);
                sub(/\)$/,Y,$0);
                A[$0]=$0;
                next
            }
     !/^s\(s/{
                B[$0]
             }
    END{
                for(j in B){
                                W=B[j];
                                for(W in A){
                                                  delete A[j]
                                           }
                           };
                for(u in A){
                                print A[u]
                           }
        }
     '  Input_file


Thanks,
R. Singh

Last edited by RavinderSingh13; 01-09-2015 at 11:41 AM.. Reason: Added non one liner form of code
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 01-10-2015
Quote:
Originally Posted by RavinderSingh13
Hello Ken6503,

Following may help you in same.
Code:
awk '/^s\(s/{sub(/^s\(/,X,$0);sub(/\)$/,Y,$0);A[$0]=$0;next} !/^s\(s/{B[$0]} END{for(j in B){W=B[j];for(W in A){delete A[j]}};for(u in A){print A}}' Input_file

Output will be as follows.
Code:
sname-pname-cprexhaa
sname-pname-abcd-phase
sname-pname-cprexrga
sname-pname-cprexloa
sname-pname-cprexmta

EDIT: Adding non oneliner command for same.
Code:
awk '/^s\(s/{
                sub(/^s\(/,X,$0);
                sub(/\)$/,Y,$0);
                A[$0]=$0;
                next
            }
     !/^s\(s/{
                B[$0]
             }
    END{
                for(j in B){
                                W=B[j];
                                for(W in A){
                                                  delete A[j]
                                           }
                           };
                for(u in A){
                                print A[u]
                           }
        }
     '  Input_file


Thanks,
R. Singh
thanks R.Singh. both codes work fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Script execution is very slow when trying to find all files and their owners on HP-UX box

Hi, I have a HP-UX server were I need to list all the files in the entire file system, their directory path, last modified date, owner and group. I do not need to search the file contents. I created the script given below and I am excluding directories and files of type tmp, temp and log. The... (4 Replies)
Discussion started by: Adyan Faruqi
4 Replies

2. Red Hat

How to find the number of cores in a Red Hat Linux box?

Hi, Could you please Tell me the command to find the number of cores in red hat box? I have tried cat cat /proc/cpuinfo | grep processor | wc -l command to find the number of processers. But need to fond the number of cores. Is there any difference between core and processor? ... (4 Replies)
Discussion started by: bikas89
4 Replies

3. Shell Programming and Scripting

find cmd works different on cron job ?

/usr/bin/find $SEARCH_DIR -daystart \( \( -name 'KI*' -a -name '*.csv' \) -o -name '*_xyz_*' \) -mtime $DAYS_AGO -printf %f -printf "\n" | sort -r > $FILES The above command gives different results when run on a cron job. When run manually the result is accurate. (2 Replies)
Discussion started by: nuthalapati
2 Replies

4. Linux

How to find remote Linux box login account without login in to that box?

Hi, How to find remote Linux box login account without login in to that box? I don't have login account at my remote Linux box. But I need who are all having login account. How do I findout? Thanks, --Muthu. (3 Replies)
Discussion started by: Muthuselvan
3 Replies

5. Shell Programming and Scripting

How to find the job and its location

Guys; I first I thank you for helping me few times in the past; A job runs every day at 8AM and looks for a file “abcd.txt” in directory “/usr/task/tmp”. How to find the job and its location. I need to change the file name to “abcd.dat”. it is UNIX environment. (2 Replies)
Discussion started by: clem2610
2 Replies

6. AIX

How to : Find Which hashing algorithem used in AIX Box ?

hello Friends , How can i identify the hashing algo used by shadow file in aix box >??? Thanks AVKlinux (1 Reply)
Discussion started by: avklinux
1 Replies

7. Shell Programming and Scripting

How to find job runtime using Autorep

Hey guys, Is there an autorep option to find out the current runtime of a job.. Or do you have to work it out using machine time and start time? What I'm trying to do is create a script that will email out the autosys job details. I was hoping there would be an autorep command that would... (0 Replies)
Discussion started by: Jazmania
0 Replies

8. Shell Programming and Scripting

Command/script to find size of Unix Box ?

Please could anyone provide me the Command/script to find the size and usage of Unix box ASAP ? (6 Replies)
Discussion started by: sakthifire
6 Replies

9. UNIX for Dummies Questions & Answers

How to insert child job under a box job?

I have this box job and it contains only one job under it which is to load a file. I want to insert a "File Watcher", "Copy File" to it? Have no clue how to do that...any help plzzz... (4 Replies)
Discussion started by: xejatt
4 Replies

10. Shell Programming and Scripting

how to find password for current user in unix box

hi all, kindly let me know the command to get password and user for current user in unix. thanks in advance. --Bali Reddy.Y (1 Reply)
Discussion started by: balireddy_77
1 Replies
Login or Register to Ask a Question