The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




Thread: tr command!
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-07-2009
c_d c_d is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
Exclamation tr command!

suppose i have a file like

Code:
//file.c

main()
{
printf("pritf");
printf("nirpt");
printf("%p%r%i%n%t%f");
}
suppose i would like to convert all the instances of "printf" to "PRINTF", the command i issued was
Code:
$ cat file.c | tr 'printf' 'PRINTF'
this is the output i got
Code:
//FIle.c

maIN()
{
PRINTF("PRITF");
PRINTF("NIRPT");
PRINTF("%P%R%I%N%T%F");
}
but that was not the output i wanted. this is the output i wanted
Code:
//file.c

main()
{
PRINTF("pritf");
PRINTF("nirpt");
PRINTF("%p%r%i%n%t%f");
}
because, neither "FIle.c" is printf, and yet it got effected by tr and neither "maIN()" is "printf" , yet it too was effected...

how do i make tr identify the entire string and then make it replace it with the desired string, instead of letting each instance of a character in the string replaced?

Last edited by c_d; 03-07-2009 at 01:57 PM..