Need script to take input from file, match on it in file 2 and input data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to take input from file, match on it in file 2 and input data
# 1  
Old 11-03-2009
Need script to take input from file, match on it in file 2 and input data

All,

I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then
Insert file1 column2 to file2 column4 then create a new file.

File1:
12345 Sam
12346 Bob
12347 Bill

File2:
Modify|Samuel|Smith||US|Indianapolis|23|12345
Modify|Robert|Smiley||US|Indianapolis|23|12346
Modify|William|Butterworth||US|Indianapolis|23|12347

So once matched and inserted new file would contain:
Modify|Samuel|Smith|Sam|US|Indianapolis|23|12345|...
Modify|Robert|Smiley|Bob|US|Indianapolis|23|12346
Modify|William|Butterworth|Bill|US|Indianapolis|23|12347

Can I do this in perl or do I need to do it somewhere else?
# 2  
Old 11-03-2009
This code in UNIX but if you have virtual machine on windows (Linux system) you can use it ....also instead of nawk (if not available) you can use gawk or /usr/xpg4/bin/awk...

Code:
nawk -v OFS="|" 'NR==FNR {a[$1]=$2 ; next}
($8 in a ){print $1,$2,$3,a[$8],$5,$6,$7,$8 ; next} {print $0}
' FS=" " file1 FS="|" file2

BR
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 get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

4. UNIX for Dummies Questions & Answers

Inserting shell script input data automatically from a text file

Dear experts, I am new to linux programming. I have a shell script which i should run it on all my samples. I only define input and out put for this script. The inputs are 3 numbers(coordination numbers) which are available in a series of text file. Since i have a lots of samples, it takes a... (5 Replies)
Discussion started by: mohamadreza
5 Replies

5. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

6. Shell Programming and Scripting

Match string from two file input

Hello all, I have file like this: file 1: aa bb cc dd ee file2: 111 111 111 111 111 111 (2 Replies)
Discussion started by: attila
2 Replies

7. Shell Programming and Scripting

adding data in input file if 2nd script output SUCCESS

Hi All, how can i edit my original data and add more data if my 2nd script outputs SUCESS? ex. input file: 1.txt nik,is,the 1script.sh if 2ndscript.sh output SUCCESS then i'm going to edit my input file and add data best,pogi.. sample outputdata. nik,is,the,best,pogi 2ndscript.sh... (3 Replies)
Discussion started by: nikki1200
3 Replies

8. Shell Programming and Scripting

List all file that match user input perl

Hi, I want to list all file that match user input ( specified shell wildcard) but when I compile it dont list me #!/usr/bin/perl -w print "Enter Advance Search Function: "; chomp ($func = <STDIN>); my @files = glob("$func"); foreach my $file (@files) { print "$file\n";... (1 Reply)
Discussion started by: guidely
1 Replies

9. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

10. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies
Login or Register to Ask a Question