Sponsored Content
Top Forums Shell Programming and Scripting encrytion/substitution issue in a file Post 302362200 by mad_man12 on Thursday 15th of October 2009 08:32:38 AM
Old 10-15-2009
)
Code:
 
ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547425069636596::6:N:mrs charles:N:PH:00010031:0001'
 
OUTPUT - ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547******636596::6:N:mrs charles:N:PH:00010031:0001'

The requirement here was to encrypt the 15th field appearing in the DEF section if the length is greater than 15

so 4547425069636596 was replaced by 4547******636596


Code:
 
awk -F":" '
BEGIN {OFS=":"}
$0 ~/\+DEF/ {
for(i=1;i<=NF;i++)
{
if($i=="+DEF")
{
if( $(i+12) ~ /[^0-9]/ )
{
next;
}
else
{
if(length($(i+12))>=15)
{
$(i+12)=substr($(12+i),1,4)"******"substr($(12+i),11,16)
}
}
}
}
}1' file_name.txt

the above code in working if have only one DEF appearing in the line, but it doesn't work if there are multiple DEF in a line it just replaces only the
first occurence of the DEF in the line and not all the occurences of DEF in the line

Code:
 
2) ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547425069636596::6:N:mrs charles:N:PH:00010031:0001+DEF:BAL:1:N::::7:450.00:0.
00:2009-04-29:XT:5286838183351672::7:N:britton:N:PH:00010031:0001+DEF:FPT:3:N::::7:10.13:0.00:2009-04-29:XT:5286838183351672::7:N:britton:N:MS:00616121:2601'
 
current output that i get
 
ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547******636596::6:N:mrs charles:N:PH:00010031:0001+DEF:BAL:1:N::::7:450.00:0.00:2009-04-29:XT:5286838183351672::7:N:britton:N:PH:00010031:0001+DEF:FPT:3:N::::7:10.13:0.00:2009-04-29:XT:5286838183351672::7:N:britton:N:MS:00616121:2601'

and i require

Code:
 
ABC::2197.12:2197.12:120217144365::+DEF:INT:1:N::::6:550.00:0.00:2009-04-29:CN:4547******636596::6:N:mrs charles:N:PH:00010031:0001+DEF:BAL:1:N::::7:450.00:0.00:2009-04-29:XT:5286******351672::7:N:britton:N:PH:00010031:0001+DEF:FPT:3:N::::7:10.13:0.00:2009-04-29:XT:5286******351672::7:N:britton:N:MS:00616121:2601'

Please Advice
 

10 More Discussions You Might Find Interesting

1. Solaris

Variable Substitution Issue

#!/bin/ksh VAR_ONE=HELLO TEMP=ONE echo $VAR_${TEMP} ## Output is: ONE Hi, I want the output to echo HELLO and not ONE as the above script does. I know I am missing something with dollar substitution. Can anyone help me out ? Thanks. Cal (4 Replies)
Discussion started by: calredd
4 Replies

2. Shell Programming and Scripting

Need help with file substitution

hello all just trying to write a script that will read a file (line by line) and substitute (tht line) in a different file if (tht line) is present in second file Ex: script has to read file A (line by line) and if file B has tht line it should get substituted with the line in file A ... (3 Replies)
Discussion started by: coolkid
3 Replies

3. Shell Programming and Scripting

Issue in substitution

Hi , I have have file which has following structure 01aaaa88888000-9999 01ssss77777000-0991 01ssss7777700000991 02ssss7777700000991 The record 01 is corrupt as value from 12th field to 19th should be positive or start with - however it is 000-9999 it should be -0009999 i need to... (4 Replies)
Discussion started by: test_user
4 Replies

4. Shell Programming and Scripting

How to change a substitution value in a file?

Hi, i want to change a subs. value in a file, with using a script.. this is my script... (example) #!/bin/bash NDIR=`zenity --file-selection --directory` mv $HOME/Desktop/myfile /tmp/myfile.temp XT='"' perl -pe "s/.*/DIR=$XT`echo -e "$NDIR"`$XT/ if $. == 40" <... (2 Replies)
Discussion started by: excsra
2 Replies

5. Shell Programming and Scripting

sed pattern substitution issue?

Hello everyone ... I'm going crazy, I hope some of you can help me ... I have to replace a line in a crontab like this: 5 2 * * 2 root backupdat with this: 5 5 * * 3 root backupdat the command I use is the following: sed -i.bak -e 's/5 2 * * 2 root backupdat/5 5 * * 3 root... (4 Replies)
Discussion started by: ionral
4 Replies

6. Shell Programming and Scripting

Issue with substitution using sed

Hi all Having issue with substitution using sed Trying to assign the absolute path of the file to the variable 'floc' returned by the find command floc=`find / -name $fname` eg cat $floc '/root/samplecheck/myfile' I want to replace '/' with '->' in the 'floc' i am using the below sed... (2 Replies)
Discussion started by: amithsebkanattt
2 Replies

7. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

8. Shell Programming and Scripting

Substitution Issue with nawk

Hi, I'm trying to reformat some badly formatted XML that I've extracted from Oracle clob columns using the following nawk command: nawk '{gsub(/&lt;/,/>\n/); print}' test.raw > test.xml the substitution executes fine, but instead of subbing &lt; with > followed by newline, it subs the &lt; with a... (3 Replies)
Discussion started by: sffuji
3 Replies

9. Shell Programming and Scripting

Multiple variable substitution in a file in one go

I have a huge script which is defining variables with full path of commands in the beginning of code and using those variables in the script. For Example: ECHO=/bin/echo LS=/bin/ls SED=/bin/sed AWK=/bin/awk UNAME=/bin/uname PS=/bin/ps DATE=/bin/date GREP=/bin/grep $ECHO "hello... (1 Reply)
Discussion started by: veeresh_15
1 Replies

10. Shell Programming and Scripting

File Extension Substitution

Hi, I have a script in which the file name is always known, but the extension could vary. I want to be able to use a single variable; no if-else statements. For example, if I have config.txt in the directory then that's what I want to use, but if config.xml is in the directory then use that. The... (9 Replies)
Discussion started by: ocbit
9 Replies
LETTERIZE(1)							    Miscellanea 						      LETTERIZE(1)

NAME
letterize_ - phone-number to letter-mnemonic generator SYNOPSIS
letterize nnnnnnn DESCRIPTION
This program tries to help you find a letter mnemonic matching a given phone number. It emits to standard output each possible pronounceable mnemonic, one per line, using the American standard mapping of dial letters to numbers (2 goes to ABC, 3 to DEF, 4 to GHI, 5 to JKL, 6 to MNO, 7 to PRS, 8 to TUV, 9 to XYZ). The program uses a table of pronounceable letter-triples derived from a dictionary scan. Each potential mnemonic must be such that all of its letter-triples are in the table to be emitted. About 30% of possible triples are considered pronounceable. A typical 7-digit phone number has 19,683 possible mnemonics, but this test usually cuts the list down to a few hundred or so, a reasonable number to eyeball-check. For some numbers, the list will, sadly, be empty. It's best to leave out punctuation such as dashes and parens. BUGS
The filtering method doesn't know what plausible medial triples are not reasonable at the beginnings and ends of words. I'm not sure what table position 0 (which is what 0 and 1 are mapped to) means. If you figure it out, you tell me. I really should have generated my own table, but that would have been more work than this seemed worth -- if your number contains either, you probably need to generate your mnemonic in disjoint pieces around the digits anyway. AUTHOR
Eric S. Raymond esr@snark.thyrsus.com. It's based on a table of plausible letter-triples that had no name attached to it. Surf to http://www.catb.org/~esr/ for updates and related resources. letterize 05/30/2012 LETTERIZE(1)
All times are GMT -4. The time now is 08:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy