![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 05: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 04:27 AM |
| formatting hard drive (scrubbing) | Jamiee | SUN Solaris | 0 | 06-12-2008 07: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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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" |
|
||||
|
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)
Code:
# python test.py "1234,0678,0987,12345667,000000976655,+1234,013994878356" "0987,78967,11243554,0000887651,1234567,09876,1234455" "0987675,6778443,797784784784,09866545,+232322,097865" |
|
||||
|
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
|
|
||||
|
Quote:
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
|
|
||||
|
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 } 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 04:43 AM.. |
| Sponsored Links | ||
|
|