Based on num of records in file1 need to check records in file2 to set some condns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Based on num of records in file1 need to check records in file2 to set some condns
# 1  
Old 11-21-2008
Based on num of records in file1 need to check records in file2 to set some condns

Hi All,

I have two files say file1 and file2.

I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions .

Could you pls help me what would be the perl script look like , i dont knw the syntax

As 'm new in this business any help is appreciated .

it wud be sumthng like

IF (file1 has atleast 2 records )
IF(file2 has atleast 1 record)
set condition1
END
ELSE-
set condition2

Currently we are using IDCAMS in mainframes to do this ...but it needs to be converted to perl scripts.If you want more elaboration , the IDCAMS code is

//STEP02 EXEC PGM=IDCAMS,COND=(0,NE)
//SYSPRINT DD SYSOUT=(,),OUTPUT=(*.JESP)
//ARCHIVO DD DSN=PRODAS.AS07.ARCHIVE(+0),DISP=(OLD,PASS)
//ARCHIVN DD DSN=PRODAS.AS07.ARCHIVE(+1),DISP=(OLD,PASS)
//SYSIN DD *
PRINT INFILE(ARCHIVO) COUNT(2)
IF LASTCC = 0 THEN -
DO
PRINT INFILE(ARCHIVN) COUNT(1) IF atleast one
IF LASTCC=4 THEN -
SET MAXCC=1
END
ELSE -
IF LASTCC=4 THEN -
SET MAXCC=0
/*
# 2  
Old 11-21-2008
This will get you the number of lines in the files

Code:
file1count=`cat <file1> | wc -l`
file2count=`cat <file2> | wc -l`

echo "File 1 has $file1count rows\n"
echo "File 2 has $file2count rows\n"

# 3  
Old 11-26-2008
its not workng in perl

not sure wat syntax to use in perl for this
# 4  
Old 11-26-2008
The example I posted is not perl, its can be run is shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check if file2 is a subset of file1?

In-order to check and print if file2 is a subset of file one i do the below. var1=$(cat //tmp/file1 | sort -u | wc) var2=$(cat /tmp/file2 /tmp/file1 | sort -u | wc) if ; then echo "file2 is a subset of file1 becoz var1 and var2 have the same values." fi However, i get the following error ... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

How-to check if file1 a subset of file2 ?

I need to know if file1 is a subset of file2 i.e all the contents of file1 are present in file2 or not. Here is how i would do it. Read line by line file1 and grep every line in file2 in a for loop. any failing grep would means that it is not a subset. Is there a quicker or easier way... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

Print sequences from file2 based on match to, AND in same order as, file1

I have a list of IDs in file1 and a list of sequences in file2. I can print sequences from file2, but I'm asking for help in printing the sequences in the same order as the IDs appear in file1. file1: EN_comp12952_c0_seq3:367-1668 ES_comp17168_c1_seq6:1-864 EN_comp13395_c3_seq14:231-1088... (5 Replies)
Discussion started by: pathunkathunk
5 Replies

4. Shell Programming and Scripting

Compare and find records of file1 not in file2

hi.. i am using solaris system and ksh and using nawk to get records of file1 not in file2(not line by line comparison). code i am using is nawk 'NR==FNR{a++} !a {print"line:" FNR"->" $0} ' file2 file1 same command with awk runs perfectly on darwin kernel(mac) but in solaris it does line by... (2 Replies)
Discussion started by: Abhiraj Singh
2 Replies

5. Shell Programming and Scripting

Match part of string in file2 based on column in file1

I have a file containing texts and indexes. I need the text between (and including ) INDEX and number "1" alone in line. I have managed this: awk '/INDEX/,/1$/{if (!/1$/)print}' file1.txt It works for all indexes. And then I have second file with years and indexes per year, one per line... (3 Replies)
Discussion started by: phoebus
3 Replies

6. Shell Programming and Scripting

Retreive the records from file2 by using the first field in file1

Hi Freinds, i have a file1 as below file1 1|ndmf|fdd|d3484|34874 2|jdehf|wru7|478|w489 3|dfkj|wej|484|49894 file2 contains lakhs of records and not in sorted order i want to retrive only the records from file2 by searcing the first field of file 1 i used grep ^1 file2... (4 Replies)
Discussion started by: i150371485
4 Replies

7. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

8. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

9. Shell Programming and Scripting

awk print only select records from file2

Print only records from file 2 that do not match file 1 based on criteria of comparing column 1 and column 6 Was trying to play around with following code I found on other threads but not too successful Code: awk 'NR==FNR{p=$1;$1=x;A=$0;next}{$2=$2(A?A:",,,")}1' FS=~ OFS=~ file1 FS="*"... (11 Replies)
Discussion started by: sigh2010
11 Replies

10. Shell Programming and Scripting

I want records in file2 those are not exist in file1

I have two files - file1 and file2. Now I want records in file2 those are not exist in file1. How to grep this ? eg: file1 08941 08944 08945 08946 08947 file2 08942 08944 5 08942 08945 5 08942 08946 4 08942 08947 6 08942 08952 4 08942 08963 5 08942 ... (3 Replies)
Discussion started by: suresh3566
3 Replies
Login or Register to Ask a Question