hi,
i have file with 4 columns, the first column contains 10 numbers. i want to replace t the numbers (u can say i want to use cryptography). i want to replace 1 with 4, 2 with 5, 3 with 9.....
how can i achieve this in unix.
When the replacement is made on the whole record, you can use the tr command.
In your case, the replacement must be made just in one field.
A possible way to do the work is to use an awk program like that :
#!/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
}
Jean-Pierre.