The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
urgent help : want to check data in oracle from flate file unknown123 Shell Programming and Scripting 3 05-18-2009 06:36 PM
how to convert the result of the select query to comma seperated data - urgent pls Hemamalini Shell Programming and Scripting 1 06-16-2008 05:27 AM
formatting hard drive (scrubbing) Jamiee SUN Solaris 0 06-12-2008 08:48 AM
Help replacing or scrubbing unicode characters roninuta Shell Programming and Scripting 3 01-21-2008 11:39 AM
[urgent need help]compare data bucci Shell Programming and Scripting 2 02-27-2007 11:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
padhu.47 padhu.47 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
Post URGENT:- Data Scrubbing

Hello World Postbit
Hi All,

I have a Flatfile (any delimitation) of millions of lines of data, where in i have to scrubb the data of the line from the position ($1 ) given in input parameter until the length ($2) given in the input parameter. I utilised awk , sed but i am unable to do it.

scrub key - 12345 should be replaced by 67890
eg: 01289 - before scrubbing
06789 - after scrubbing


example : sample.ksh 6 4



Input - Flatfile:
-------
"1234,5678,0987,12345667,000000976655,+1234,013994878356"
"0987,23467,11243554,0000887651,1234567,09876,1234455"
"0987675,1223443,797784784784,09866545,+232322,097865"

I want the output as scrubbed file as below:

"1234,0678,0987,12345667,000000976655,+1234,013994878356"
"0987,78967,11243554,0000887651,1234567,09876,1234455"
"0987675,6778443,797784784784,09866545,+232322,097865"
  #2 (permalink)  
Old 05-26-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
if you have Python

Code:
#!/usr/bin/env python
import string
FROM="12345"
TO="67890"
table=string.maketrans(FROM,TO)
for line in open("file"):
    line=line.strip().split(",")
    line[1]=line[1][:4].translate(table) + ''.join(line[1][4:])
    print ','.join(line)

output

Code:
# python test.py
"1234,0678,0987,12345667,000000976655,+1234,013994878356"
"0987,78967,11243554,0000887651,1234567,09876,1234455"
"0987675,6778443,797784784784,09866545,+232322,097865"

  #3 (permalink)  
Old 05-26-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092

Code:
sub scrub{
	my($pos,$len)=(@_);
	while(<DATA>){
		substr($_,$pos-1,$len) =~ y/12345/67890/;
		print $_;
	}
}
scrub(6,3);
__DATA__
1234,5678,0987,12345667,000000976655,+1234,013994878356
0987,23467,11243554,0000887651,1234567,09876,1234455
0987,1223443,797784784784,09866545,+232322,097865

  #4 (permalink)  
Old 05-26-2009
padhu.47 padhu.47 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
URGENT:- Data scrubbing

Hi All, thanks for the reply ....
i dont have python or perl ....
I have only ksh, bash, sh, csh

please help me
  #5 (permalink)  
Old 05-26-2009
Neo's Avatar
Neo Neo is online now Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,823
Quote:
Originally Posted by padhu.47 View Post
Hi All, thanks for the reply ....
i dont have python or perl ....
I have only ksh, bash, sh, csh

please help me
Better to install PERL or Python. It is free and easy to install.
  #6 (permalink)  
Old 05-26-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Quote:
Originally Posted by padhu.47 View Post
Hi All, thanks for the reply ....
i dont have python or perl ....
I have only ksh, bash, sh, csh

please help me
then use awk

Code:
awk -F"," 'BEGIN{
 t["1"]="6"
 t["2"]="7"
 t["3"]="8"
 t["4"]="9"
 t["5"]="0" 
}
{
 s=""
 for(i=1;i<=4;i++){
  if( substr($2,i,1) in t ){
     s=s t[substr($2,i,1)]
  }else{
     s=s substr($2,i,1)
  }   
 }
 $2=s substr($2,5)
}
1
' OFS="," file

  #7 (permalink)  
Old 05-27-2009
padhu.47 padhu.47 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 4
URGENT:- Data Scrubbing

the above code is not working .....
please help me in writing this code in KSH,CSH,SH....

-----Post Update-----

hello guys,

I have wrote a awk prog ...as below to do it. but its doing for all the numbers inside the flatfile.

code#:
#!/usr/bin/awk -f
BEGIN {
CnvFrom = "0123456789";
CnvTo = "4590382617";

Field = 1;
}
{
newField = ""
for (i=1; i<=length($Field); i++) {
char = substr($Field, i, 1);
if (pos=index(CnvFrom, char))
char = substr(CnvTo, pos, 1)
newField = newField char
}
$Field = newField
print
}


But my requirment is to change/translate the values from the position(input parameter - $2) and length (input parameter - $3) for the flatfile mentioned in a directory (input parameter - $1). please help me ....

eg : scrub.ksh file1 68 9 ( $1 - filename, $2 -postion (68), $3 - lenth from position (9) )

Before scrub- file1:
---------------------
"37713000000","12000000202","0000000000000000000007102","0000377310013683931",20090114,20080301,20080331,20060304,+000000000005897."
"37713000000","12000000202","0000000000000000000007102","0000377310013683931",20090114,20080301,20080331,20060304,+000000000005897."
"37713000000","12000000202","0000000000000000000010739","0000377310044493243",20090114,20080501,20080531,20070224,+000000000000000."
"37713000000","12000000202","0000000000000000000010739","0000377311018365607",20090114,20080401,20080430,20070224"


After scrub -file1:
-----------------

"37713000000","12000000202","0000000000000000000007102","0000377310450210705",20090114,20080301,20080331,20060304,+000000000005897."
"37713000000","12000000202","0000000000000000000007102","0000377310450210705",20090114,20080301,20080331,20060304,+000000000005897."
"37713000000","12000000202","0000000000000000000010739","0000377310433370930",20090114,20080501,20080531,20070224,+000000000000000."
"37713000000","12000000202","0000000000000000000010739","0000377311451028246",20090114,20080401,20080430,20070224"

please help me ..... i want the scrub as per the input parameters.....
please help ....

Last edited by padhu.47; 05-27-2009 at 05:43 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0