Bash of records into file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash of records into file
# 1  
Old 05-16-2016
Bash of records into file

Hi All,

Seeking for your assistance to check if there a file PROS containing on the file1.txt and display the missing PROS file.

Code:
cat file1.txt
049|0276
230|0457
094|0134
094|1268
080|0445
049|1896

Code:
cd home/sysad
PROS0490276042017.TXT
PROS2300457042017.TXT

Code:
expected output:
missing PROS File:
PROS0940134
PROS0941268
PROS0800445
PROS0491896

Code:
so far what i did was awk the file1.txt
list=`awk -F "|" '{print $1$2}' file1.txt`

i don't know if read line is the correct code
while read line
do
 ls PROS$list*
 <i don't know next if there's a non matching file how do i print it.>

Please advise,

Thanks,
# 2  
Old 05-16-2016
Try
Code:
ls home/sysad/PROS* | awk 'NR == FNR {T[substr($1, 5, 7)] = $1; next} !($1$2 in T) {print "PROS" $1 $2}' FS="|" - file1
PROS0940134
PROS0941268
PROS0800445
PROS0491896

This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-16-2016
Hi RudiC,
I think solution need 6 character to extract instead 7
Code:
substr($1, 5, 7)

Thanks
Pravin
This User Gave Thanks to pravin27 For This Post:
# 4  
Old 05-16-2016
Hi Sir RudiC,

Would you mind explaining it to me?

Thanks,
# 5  
Old 05-16-2016
Hello znesotomayor,

Could you please try following and let me know if this helps.
Code:
awk 'BEGIN{print "missing PROS File:"} {gsub(/\|/,X,$0);system("find . -type f -iname *" $0 "* > temp_file");file="temp_file";Q=getline<file;if(!Q){print "PROS" $0};print Q;if(Q){system("rm temp_file")}}'  Input_file

EDIT:Also in above command you could change command to as follows too where you could mention the path from where you want to look for the files.
Code:
awk 'BEGIN{print "missing PROS File:"} {gsub(/\|/,X,$0);system("find /singh/is/king/path -type f -iname *" $0 "* > temp_file");file="temp_file";Q=getline<file;if(!Q){print "PROS" $0};print Q;if(Q){system("rm temp_file")}}'  Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 05-16-2016 at 08:23 AM.. Reason: Added a small comment and improved solution for same now too.
# 6  
Old 05-16-2016
by the way i'm using shell. my output is different.

---------- Post updated at 07:22 PM ---------- Previous update was at 07:12 PM ----------

Hi Sir R. Singh,

Please see output below:

Code:
[dbadmin@BIDBPD1 test]$ awk 'BEGIN{print "missing PROS File:"} {gsub(/\|/,X,$0);system("find . -type f -iname *" $0 "* > temp_file");file="temp_file";Q=getline<file;if(!Q){print "PROS" $0}} END{system("rm temp_file")}'  file1.txt
missing PROS File:
PROS2300457
PROS0940134
PROS0941268
PROS0800445
PROS0491896
[dbadmin@BIDBPD1 test]$ cat file1.txt
049|0276
230|0457
094|0134
094|1268
080|0445
049|1896

PROS2300457 is included although there's already a file on it.

Thanks,

---------- Post updated at 07:39 PM ---------- Previous update was at 07:22 PM ----------

Hi Sir Pravin,

I don't see an output on my side. is there a difference if my file directory is different?

Please advise,

Thanks,
# 7  
Old 05-16-2016
Those "PROS" files are listed and piped into awk, which collects them into the T array. Then file1 is read and each line's values compared against the indices of the T array. If not found, "PROS" plus the values are printed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies

2. 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

3. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

4. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

5. Shell Programming and Scripting

count and compare no of records in bash shell script.

consider this as a csv file. H,0002,0002,20100218,17.25,P,barani D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 D,1,2,3,4,5,6,7,8,9,10,11 T,5 N i want to read the csv file and count the number of rows that start with D and... (11 Replies)
Discussion started by: barani75
11 Replies

6. Shell Programming and Scripting

Bash Scripting Search For Records

Hi, I urgently need help with an assignment I must complete by tomorrow. I started Bash Scripting yesterday so am a complete newbie. I don't have time to teach myself Bash scripting so please don't redirect me to some tutorials. The assignment I have to do involves the following: the aim... (1 Reply)
Discussion started by: isxrc
1 Replies

7. UNIX for Dummies Questions & Answers

Bash script to extract spf records

Hello I am trying to generate a script to run on worldwide firewalls. I need the spf block for large sites like google, etc so I can essentially whitelist google sites for users. (Google here is just an example...) Right now I am just testing Bash oneliners to see how I can isolate the... (1 Reply)
Discussion started by: mbubb
1 Replies

8. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: mavesum
3 Replies

9. UNIX for Dummies Questions & Answers

Use records from one file to delete records in another file

file_in_1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 file_in_2: 9 10 11 12 21 22 23 24 1 2 3 4 17 18 19 20 file_out: (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question