Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am having following problem in linux environment.
I have a following basic file with name " BASEFILE", as shown example below :
sl.no pol.no name status loan
1 123 rama FORCE 500
2 234 jama LAPSE 800
3 345 kama FORCE 900
4 456 lama FORCE 550
5 567 nama WDRAW 650
6 678 sama SURRD 750
7 789 pama FORCE 850
Now I want outputfile with name "OUTPUTFILE" for only few pol nos
like
123
789
678
ie,1. MY OUTPUT FILE IS TO BE WITH ALL THE COLUMNS for THOSE ONLY 3 POL
2. MY OUTPUT FILE IS TO BE WITH SELECTED COLUMNS SAY name and status ,ONLY FOR 3 POLICIES.
( in my work environment, iam having a basic file with 195000 rows and i want output file for only 57000 policies, such the case )
I request you to suggest the command for drawing such output file.
, if awk programme is necessary, pl tell me where, and how to write such
programme.
Pl guide me
Thanks Druuna... Great points.. After I posted, I noticed that the input file might also have " 123 " in the loan field so the awk method is the best way so that you are only looking at second field.
like 123 678, i have to at a stretch i need outputfile with 57000 entries, like 123,678,789,...... (570000).
It is little bit difficult to write all the nos in command line. pl help me in getting output file for all those 57000 entries from base file of 195000.
Pl guide me.
Rao
- Where are these 57000 stored?
- How are they stored?
Both not mentioned in your original post and how are we to know that this and i want output file for only 57000 policies means you have 57000 policies floating around somewhere and that is the input? I see no good reason to flag all answers as unhelpful if your initial description of the problem is (partially) incorrect.....
Dear friend, I have in my first posting also i have noted that out of a base file with 195000 i want output file for 57000 entries. ( pl see in brackets in my first posting.)
Further my problem is like this,
in my office policy data master file is with 195000 policy numbers with various details like loan amount, status, name of policyholder, address, commencement date like so.
Now another data file with 57000 i have recd from our higher office in linux format ie policy numbers are in the filed 1 to 9 , ie 123456789
325645893
256321456
.... like so (570000 policy nos)
Now my higher office requires a out put file with the following fields for all the 57000 policies
field like status, loanamount,name, address etc.
That is the reason, i have a given a test example for my above situation.
ie for few nos , output file is required with mentioned fields from the base file.
How to get output file from a master file-pl see my earlier posting
Dear friend, I have in my first posting also i have noted that out of a base file with 195000 i want output file for 57000 entries. ( pl see in brackets in my first posting.)
Further my problem is like this,
in my office policy data master file is with 195000 policy numbers with various details like loan amount, status, name of policyholder, address, commencement date like so.
Now another data file with 57000 i have recd from our higher office in linux format ie policy numbers are in the filed 1 to 9 , ie 123456789
325645893
256321456
.... like so (570000 policy nos)
Now my higher office requires a out put file with the following fields for all the 57000 policies
field like status, loanamount,name, address etc.
That is the reason, i have a given a test example for my above situation.
ie for few nos , output file is required with mentioned fields from the base file.
First of all: Both aka_norm and me never understood from your first post what is was you wanted. And I did read what's between the braces (I even quoted from it and told you it was not clear). Please be as precise as possible when describing your problem and keep in mind that you might not have been understood before pushing Thanks/Yes/No buttons.......
Code:
#!/bin/bash
policyFile="policyfile"
inFile="INFILE"
outFile="OUTPUTFILE"
> $OUTPUTFILE
while read polNo
do
awk '$2=='$polNo'' $inFile >> $outFile
done < $policyFile
Example run:
Code:
$ cat INFILE
sl.no pol.no name status loan
1 123 rama FORCE 500
2 234 jama LAPSE 800
3 345 kama FORCE 900
4 456 lama FORCE 550
5 567 nama WDRAW 650
6 678 sama SURRD 750
7 789 pama FORCE 850
$ cat policyfile
123
789
678
$ ./extract.sh
$ cat OUTPUTFILE
1 123 rama FORCE 500
7 789 pama FORCE 850
6 678 sama SURRD 750
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. Your threads have been merged.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.