How to sca a sequential file and fetch some substring data from it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sca a sequential file and fetch some substring data from it
# 1  
Old 10-29-2008
How to sca a sequential file and fetch some substring data from it

Hi,
I have a task where i need to scan second column of seuential file and fetch first 3 digits of that column

For e.g. FOLLOWING IS THE SAMPLE FOR MY SEQUENTIAL FILE

AU_ID ACCT_NUM CRNCY_CDE
THHSBC001 30045678 THB
THHSBC001 10154267 THB
THHSBC001 10278976 USD
THHSBC001 72876276 THB

In this, i need fetch 300, 101, 102, 728 let us say them ID
I need to fetch them sequentially like, first fetch 300 and also i need to compare this with a DB table (Look up table)which looks like

ID SRC Country Code

300 OHC INM
101 OHC SGH
102 OHC MYH

if those ID from sequential file is present in look up table then i need to fetch the whole record and put that into a separate sequential file named same as country code of look up table.

so in this e.g., ID that is fetched from sequential file is 300 and it is also present into look up table then whole record from the sequential file should go into another sequential file named as INM ( country code corresponding to 300)

Please can anybody help me with this ASAP...

it will be really appreciated..

Thanks
# 2  
Old 10-29-2008
Hi,
There are tons of this kind of questions in this forum, why not just search and learn a little bit.

Here is the code:
Code:
awk 'NR==FNR {_[$1]; next}
        substr($2, 1,3) in _ {print $0}
        ' lookup_filename sequential_filename > output_filename

# 3  
Old 10-29-2008
Thanks ......Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch data from file

Hi, I am new to scripting. I have a log file and need to fetch specific logs and copy to another file. A copy of the log is like this: =============================================================== = JOB : server123#jobs1.jobstream1 = USER : andyc = Tue 08/01/17... (3 Replies)
Discussion started by: Prngp
3 Replies

2. UNIX for Beginners Questions & Answers

How to fetch specific data from a file.?

Hi , I have a file which contains 2 days logs(here it is 24 and 25) I want to list data only for date 25 fron the file. please suggest me how should i get this. file content mentioned below 17-05-24 Name Succ Fail 00:00:29 ... (5 Replies)
Discussion started by: scriptor
5 Replies

3. Shell Programming and Scripting

Execute sequential files and store data in single file

1)In a particualr path i have a set of inputfiles like path:/defaultmis/MonthlyLoads/INFA_EXPORT_022013/map* example: 1)map_de 2)map_cod 3)map_feg ........and so on in above path there wil be nearly 15 to 20 files starting with map and in other path i have another file input file... (4 Replies)
Discussion started by: katakamvivek
4 Replies

4. Shell Programming and Scripting

Fetch data between two dates from a file

Hi All, I m new to this forum & UNix too. currently i have a requirement which can fetch data from a logfile between two dates or timestamp. for example: 1. data from 2012 Jun to 2012 Jul 2. data from 2012 Jun to 2012 Jul 07 3. data from 2012 Jun 16 10:20 to 2012 Jul 03 10:10 Please... (7 Replies)
Discussion started by: KDMishra
7 Replies

5. Shell Programming and Scripting

How to fetch data between two timestamps in a file using KSH

Hi, I got a requirement to fetch data between two time stamps in a big log file and grep for a word in that particular time interval of data. Here is my log looks like: 2012/04/08-14:35:56 Abcdefg 2012/04/08-14:35:56 Hijklmnophhoishfw 2012/04/08-14:35:56... (1 Reply)
Discussion started by: siri_886
1 Replies

6. Shell Programming and Scripting

how to fetch substring from records into another file

Hi all, Im stuck in findind solution to ths problem. Please guide me if u have any ideas. I have two files. ===FILE1=== >bi|2138271|geb|AAC15885.1|precursor MRVIAAAMLYLYIVVLAICSVGIQGIDYPSVSFNLAGAKSATWDFLRMPHDLVGEDNKYNDGEPITGNII... (25 Replies)
Discussion started by: smriti_shridhar
25 Replies

7. Shell Programming and Scripting

how to scan a sequential file to fetch some of the records?

Hi I am working on a script which needs to scan a sequential file and fetch the row where 2nd column = 'HUB' Can any one help me with this... Thanks (1 Reply)
Discussion started by: manmeet
1 Replies

8. Shell Programming and Scripting

fetch substring from html code

hello mates. please help me out once again. i have a html file where i want to fetch out one value from the entire html-code sample html code: ..... <b>Amount:<b> 12345</div> ... now i only want to fetch the 12345 from the html document. how to i tell sed to get me the value from... (2 Replies)
Discussion started by: scarfake
2 Replies

9. Shell Programming and Scripting

How to fetch data from a text file in Unix

I want to fetch passwords from a common file xxxx.txt and use it in a script. Currently the password is hardcoded so this have to be changed so that password can be fetched from text file..... Please reply asap.. Thanks (4 Replies)
Discussion started by: shikhakaul
4 Replies

10. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies
Login or Register to Ask a Question