Hello,
This is my first post.
I have a problem that I have nearly solved, I need some help to complete it.
I have 2 files.
input.txt (6000 lines) looks like this:
BT04 1LG,UniqueID1,Type1
BT19 6SF,UniqueID2,Type1
BT22 4PT,UniqueID3,Type2
BT19 5SF,UniqueID4,Type2
database.txt (750,000 lines) looks like this:
BT22 4PT,350432,237859
BT19 5SF,374650,384950
BT04 1LG,238400,438900
BT44 8DF,237465,849503
BT04 1LG,238475,483928
BT19 6SF,384758,948372
The desired output is:
"$2input.txt,$3input.txt,$2database.txt,$3database.txt" where $1==$1
UniqueID1,Type1,238475,483928
UniqueID1,Type1,238400,483900
Note: $1 in input.txt will match several records in database.txt
I have been able to output the desired results with an input file containing 1 record, however I need to do this with 6000 records.
My script looks like this:
########################################
#!/bin/bash
# These lines read the input file and assign variables
postcode=`cat input.txt | awk -F, '{ print $1 }'`
id=`cat input.txt | awk -F, '{ print $2 }'`
type=`cat input.txt | awk -F, '{ print $3 }'`
## This line reads in the database file, matches $1 in input file with S1 in database, and outputs the id and type from the input file followed by the remaining information from the database file
cat database.txt | awk -F, -v post="$postcode" '$1==post {print "'$id'"",""'$type'"","$2","$3}' > results.txt
########################################
How do I make this script run on all 6000 lines of the input file?
Is it possible to do it like this or is there an better way?
I am relatively new to shell scripting and any help you can give me would be most appreciated.
Thanks
Alex
This is my first post.
I have a problem that I have nearly solved, I need some help to complete it.
I have 2 files.
input.txt (6000 lines) looks like this:
BT04 1LG,UniqueID1,Type1
BT19 6SF,UniqueID2,Type1
BT22 4PT,UniqueID3,Type2
BT19 5SF,UniqueID4,Type2
database.txt (750,000 lines) looks like this:
BT22 4PT,350432,237859
BT19 5SF,374650,384950
BT04 1LG,238400,438900
BT44 8DF,237465,849503
BT04 1LG,238475,483928
BT19 6SF,384758,948372
The desired output is:
"$2input.txt,$3input.txt,$2database.txt,$3database.txt" where $1==$1
UniqueID1,Type1,238475,483928
UniqueID1,Type1,238400,483900
Note: $1 in input.txt will match several records in database.txt
I have been able to output the desired results with an input file containing 1 record, however I need to do this with 6000 records.
My script looks like this:
########################################
#!/bin/bash
# These lines read the input file and assign variables
postcode=`cat input.txt | awk -F, '{ print $1 }'`
id=`cat input.txt | awk -F, '{ print $2 }'`
type=`cat input.txt | awk -F, '{ print $3 }'`
## This line reads in the database file, matches $1 in input file with S1 in database, and outputs the id and type from the input file followed by the remaining information from the database file
cat database.txt | awk -F, -v post="$postcode" '$1==post {print "'$id'"",""'$type'"","$2","$3}' > results.txt
########################################
How do I make this script run on all 6000 lines of the input file?
Is it possible to do it like this or is there an better way?
I am relatively new to shell scripting and any help you can give me would be most appreciated.
Thanks
Alex