If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Scramble solution

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-08, 09:31
varun_751980 varun_751980 is offline
Registered User
 
Join Date: Nov 2003
Location: India
Posts: 114
Scramble solution

I have a file in UNIX. Each record in the file is 852 characters.

As per my requirement I have to replace the contents of file in each record from position 38 to 348 as “*”. These fields will have very sensitive data and we want to hide it with *.

I tried sed using –r option but the –r option doesn’t work.

Could you people please suggest something using AWK , SED or whatever. This is a urgent requirement.
Reply With Quote
  #2 (permalink)  
Old 12-08-08, 12:47
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Untested:
Code:
sed -e 's/\(.........38x....\).*/\1***********310x*****/g'
Or you can cut the first 38 characters from each line and concatenate it with 310x *.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 12-08-08, 12:57
varun_751980 varun_751980 is offline
Registered User
 
Join Date: Nov 2003
Location: India
Posts: 114
cThanks for the reply. But I don't want to use 310 asterik * signs... Can some command or loop help me in this
Reply With Quote
  #4 (permalink)  
Old 12-09-08, 05:55
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
This what you want to do?
Lets assume you need to replace columns 15-20 with a single *
Code:
cat xx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
----+----1----+----2----+-

cut -c 1-15,21- <xx | sed 's/./*/15'
ABCDEFGHIJKLMN*UVWXYZ
----+----1----*----+-
Reply With Quote
  #5 (permalink)  
Old 12-09-08, 11:49
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Talking Or maybe....

Or maybe this?:
Code:
$ beg=15
$ end=20
$ echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ"|\
> awk -v r="$beg,$end" 'BEGIN {split(r,q,",");for (i=q[1];i<=q[2];++i) a=a"*";}
> {o=substr($0,1,q[1]-1) a substr($0,q[2]+1); print o;}' 
ABCDEFGHIJKLMN******UVWXYZ
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On