The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Translate Toolkit 1.1.1 (Default branch) iBot Software Releases - RSS News 0 03-27-2008 05:50 AM
Trouble with UNIX tr (translate) function by_tg UNIX for Dummies Questions & Answers 2 01-30-2008 03:23 PM
Can someone help translate this snippet? Heron Shell Programming and Scripting 7 03-28-2005 11:01 PM
Cannot translate Unix executable files Steven Greenber OS X (Apple) 1 02-11-2004 11:14 AM
translate text (1 position) with sed peterk Shell Programming and Scripting 5 12-12-2003 01:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2008
Registered User
 

Join Date: Mar 2008
Posts: 12
how to achicve translate in unix

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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-31-2008
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
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 :
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
   print
}
Jean-Pierre.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0