Extracting a portion of the string and comparing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting a portion of the string and comparing
# 1  
Old 07-21-2011
Extracting a portion of the string and comparing

I have 2 text files say file1.txt and file2.txt . Some of the sample records for file1.txt were shown below:

XXXXX12345XXXXXXX12 3456789YYYYY
XXXXXXXXXX12345XX123457485YYYYY
XX12345XXXXXXXXXX123454658YYYYY

for file2.txt, some of the sample records were shown below:

XXXXXX12345656577ZZZZZZZZZZZZZZZZ
TTTTTTT12345837835ZZZZZZZZZZZZZZZZZ
ZZZZZZZ6385 64658YYYYYYYYYYYYYYY
XXXXXXXXXXXXXXXX12 3456789YYYYY

I need to find the common records that were present in file2.txt with respect to file1.txt provided THE ACCOUNT NUMBERS IN THE FILE2 SHUD BE COMPARED WITH FILE1 at particular postion from 18-26 only. It shud not take other relevant positions into consideration.

Any help could be really appreciated.

---------- Post updated at 02:31 PM ---------- Previous update was at 02:17 PM ----------

Help Help
# 2  
Old 07-21-2011
Are the account number located in the same positions 18-26 in both files?
# 3  
Old 07-21-2011
Quote:
Originally Posted by Shell_Life
Are the account number located in the same positions 18-26 in both files?

No..they are located at different positions I suppose
# 4  
Old 07-21-2011
See this works for you:
Code:
sed 's/.\{17\}\(.\{9\}\).*/\1/' File2 > File2.acct
egrep -f File2.acct File1

# 5  
Old 07-21-2011
Quote:
Originally Posted by Shell_Life
See this works for you:
Code:
sed 's/.\{17\}\(.\{9\}\).*/\1/' File2 > File2.acct
egrep -f File2.acct File1


That doesnt work..

---------- Post updated at 03:46 PM ---------- Previous update was at 03:39 PM ----------

Quote:
Originally Posted by Shell_Life
See this works for you:
Code:
sed 's/.\{17\}\(.\{9\}\).*/\1/' File2 > File2.acct
egrep -f File2.acct File1


sed 's/.\{17\}\(.\{9\}\).*/\1/' File2 > File2.acctThis has yielded all the account numbers from file1..what to do next ?
# 6  
Old 07-21-2011
handles that pesky embedded space...

Code:
for i in $(cut -c 18-26 </tmp/file1.txt |tr ' ' '^' ) ;do echo $i ;grep -n "$(echo $i |tr '^' ' ')" /tmp/file2.txt ;done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting directory portion.

Dear Experts, I have some directory structure something like follows. I would like to cut portion of it. Would you please help me? I have to run this on several sql's. The directory path is dynamic. I have cut what comes after first "sql" string. Input:... (3 Replies)
Discussion started by: srikanth38
3 Replies

2. Shell Programming and Scripting

Get portion of string from the end

Hi all, Can anyone suggest a way to get a portion of string from the end? So: $ORACLE_SID=blt10cr1 We can drop the final '1' and end up with: $ORACLE_SID=blt10cr So far I have the following: echo $ORACLE_SID | cut -c1-5 and echo $ORACLE_SID | cut -c1-6 | rev any ideas? (4 Replies)
Discussion started by: jonnyd
4 Replies

3. Shell Programming and Scripting

Extracting a portion of the filename

Hi I would like to extract the first portion of filename from a list of files. The filename pattern is of the form 123456789_TEXT_TEXT_TEXT_.csv. I want to extract just the numerical portion of this filename from the list of files and then output this into another text file. K (6 Replies)
Discussion started by: kamal_p_99
6 Replies

4. Shell Programming and Scripting

How to extract portion of a string?

Hi Gurus, Would like to seek some help on how to extract a portion of string from log's output as shown below. Sample of raw data: piece handle=/test123/disk_dump/test123/df0_cntrl_PCPFCI20120404_68498 tag=TAG20120404T180035 comment=NONE piece... (13 Replies)
Discussion started by: superHonda123
13 Replies

5. Shell Programming and Scripting

Remove first portion of string

I have a script which currently uses a file containing a list of directories as an argument. The file is read in to an array, and then the array is iterated in a for loop. What I would like to do is cut off the first few directories of the directory path (they won't exist on the server where the... (5 Replies)
Discussion started by: msarro
5 Replies

6. Shell Programming and Scripting

Help on extracting portion of string

Hi Gurus, I've some sample of my log information as shown below. -> Processing ABCD123456 This is tp version 372.04.57 (release 700, unicode enabled) This is R3trans version 6.14 (release 700 - 05.03.09 - 08:28:00). unicode enabled version R3trans finished (0000). Warning: Parameter... (1 Reply)
Discussion started by: superHonda123
1 Replies

7. Shell Programming and Scripting

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

8. Shell Programming and Scripting

Extracting a portion of a data file with identifier

Hi, I do have a TAB delimted text file with the following format. 1 (- identifier of each group. this text is not present in the file only number) 1 3 4 65 56 WERTF 2 3 4 56 56 GHTYHU 3 3 5 64 23 VMFKLG 2 1 3 4 65 56 DGTEYDH 2 3 4 56 56 FJJJCKC 3 3 5 64 23 FNNNCHD 3 1 3 4 65 56 JDHJDH... (9 Replies)
Discussion started by: Lucky Ali
9 Replies

9. UNIX for Dummies Questions & Answers

Stripping a portion of string from behind!!!

Hi, How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007 i want to remove .Mar-17-2007...is there a one line command which can give this output... Thanks Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies

10. UNIX for Dummies Questions & Answers

How to extract a portion of a string from the whole string

How to extract a portion of a string from a full string using unix. For example: Say source string is = "req92374923.log" I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Discussion started by: ds_sastry
2 Replies
Login or Register to Ask a Question