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



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bash while read how to remove \n character papasj Shell Programming and Scripting 3 05-25-2009 09:24 PM
Can I read a file character by character? murtaza Shell Programming and Scripting 4 04-27-2009 05:51 AM
Can i read a file character by character karnan Shell Programming and Scripting 6 05-19-2008 02:22 AM
Read First Character of Each Line in File azelinsk Shell Programming and Scripting 7 07-11-2007 08:15 PM
need to read 3° character from a text file piltrafa UNIX for Dummies Questions & Answers 15 07-26-2005 10:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-06-2008
vipervenom25 vipervenom25 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 1
read a variable character by character, substitute characters with something else

im having trouble doing this:

i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba

is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's?

im guessing its like getting the 1's compliment of the string

im doing this in BASH, and ive looked into seeing if sed or awk could help but i got nothing

any help would be greatly appreciated
thanks
  #2 (permalink)  
Old 06-06-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
echo $var | tr a z | tr b a | tr z b

more info: man tr
we use z as temporary placeholder as we can only transform one character a time
  #3 (permalink)  
Old 06-06-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink I think you may need to use a 'dummy' character

In order to switch things, the first cannot immediately be switched to the second. Take a look at the following where I ...
translate a to z
translate b to a
translate z to b

Code:
> echo $var1
aababbbaaaababaabbaabbba
> var2=$(echo $var1 | tr a z)
> var3=$(echo $var2 | tr b a)
> var4=$(echo $var3 | tr z b)
> echo $var4
bbabaaabbbbababbaabbaaab
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0