10-15-2009
encrytion/substitution issue in a file
1) 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
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
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
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
#!/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
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
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
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
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
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
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
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(/</,/>\n/); print}' test.raw > test.xml
the substitution executes fine, but instead of subbing < with > followed by newline, it subs the < with a... (3 Replies)
Discussion started by: sffuji
3 Replies
9. Shell Programming and Scripting
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
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
LEARN ABOUT DEBIAN
rrdgraph_data
RRDGRAPH_DATA(1) rrdtool RRDGRAPH_DATA(1)
NAME
rrdgraph_data - preparing data for graphing in rrdtool graph
SYNOPSIS
DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<time>][:end=<time>][:reduce=<CF>]
VDEF:vname=RPN expression
CDEF:vname=RPN expression
DESCRIPTION
These three instructions extract data values out of the RRD files, optionally altering them (think, for example, of a bytes to bits
conversion). If so desired, you can also define variables containing useful information such as maximum, minimum etcetera. Two of the
instructions use a language called RPN which is described in its own manual page.
Variable names (vname) must be made up strings of the following characters "A-Z, a-z, 0-9, -,_" and a maximum length of 255 characters.
When picking variable names, make sure you do not choose a name that is already taken by an RPN operator. A safe bet it to use lowercase or
mixed case names for variables since operators will always be in uppercase.
DEF
DEF:<vname>=<rrdfile>:<ds-name>:<CF>[:step=<step>][:start=<time>][:end=<time>][:reduce=<CF>]
This command fetches data from an RRD file. The virtual name vname can then be used throughout the rest of the script. By default, an RRA
which contains the correct consolidated data at an appropriate resolution will be chosen. The resolution can be overridden with the --step
option. The resolution can again be overridden by specifying the step size. The time span of this data is the same as for the graph by
default, you can override this by specifying start and end. Remember to escape colons in the time specification!
If the resolution of the data is higher than the resolution of the graph, the data will be further consolidated. This may result in a graph
that spans slightly more time than requested. Ideally each point in the graph should correspond with one CDP from an RRA. For instance,
if your RRD has an RRA with a resolution of 1800 seconds per CDP, you should create an image with width 400 and time span 400*1800 seconds
(use appropriate start and end times, such as "--start end-8days8hours").
If consolidation needs to be done, the CF of the RRA specified in the DEF itself will be used to reduce the data density. This behavior can
be changed using ":reduce=<CF>". This optional parameter specifies the CF to use during the data reduction phase.
Example:
DEF:ds0=router.rrd:ds0:AVERAGE
DEF:ds0weekly=router.rrd:ds0:AVERAGE:step=7200
DEF:ds0weekly=router.rrd:ds0:AVERAGE:start=end-1h
DEF:ds0weekly=router.rrd:ds0:AVERAGE:start=11:00:end=start+1h
VDEF
VDEF:vname=RPN expression
This command returns a value and/or a time according to the RPN statements used. The resulting vname will, depending on the functions used,
have a value and a time component. When you use this vname in another RPN expression, you are effectively inserting its value just as if
you had put a number at that place. The variable can also be used in the various graph and print elements.
Example: "VDEF:avg=mydata,AVERAGE"
Note that currently only aggregation functions work in VDEF rpn expressions. Patches to change this are welcome.
CDEF
CDEF:vname=RPN expression
This command creates a new set of data points (in memory only, not in the RRD file) out of one or more other data series. The RPN
instructions are used to evaluate a mathematical function on each data point. The resulting vname can then be used further on in the
script, just as if it were generated by a DEF instruction.
Example: "CDEF:mydatabits=mydata,8,*"
About CDEF versus VDEF
At some point in processing, RRDtool has gathered an array of rates ready to display.
CDEF works on such an array. For example, CDEF:new=ds0,8,* would multiply each of the array members by eight (probably transforming bytes
into bits). The result is an array containing the new values.
VDEF also works on such an array but in a different way. For example, VDEF:max=ds0,MAXIMUM would scan each of the array members and store
the maximum value.
When do you use VDEF versus CDEF?
Use CDEF to transform your data prior to graphing. In the above example, we'd use a CDEF to transform bytes to bits before graphing the
bits.
You use a VDEF if you want max(1,5,3,2,4) to return five which would be displayed in the graph's legend (to answer, what was the maximum
value during the graph period).
If you want to apply 'complex' operations to the result of a VDEF you have to use a CDEF again since VDEFs only look like RPN expressions,
they aren't really.
SEE ALSO
rrdgraph gives an overview of how rrdtool graph works. rrdgraph_data describes DEF,CDEF and VDEF in detail. rrdgraph_rpn describes the
RPN language used in the ?DEF statements. rrdgraph_graph page describes all of the graph and print functions.
Make sure to read rrdgraph_examples for tips&tricks.
AUTHOR
Program by Tobias Oetiker <tobi@oetiker.ch>
This manual page by Alex van den Bogaerdt <alex@vandenbogaerdt.nl> with corrections and/or additions by several people
1.4.7 2009-10-14 RRDGRAPH_DATA(1)