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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
More than transposing! bulash UNIX Desktop for Dummies Questions & Answers 3 04-11-2008 05:20 PM
Transposing string unibboy Shell Programming and Scripting 3 02-13-2008 06:12 PM
Major Awk problems (Searching, If statements, transposing etc.) Blivo Shell Programming and Scripting 2 09-05-2007 06:41 AM
Another transposing issue stevesmith Shell Programming and Scripting 14 09-16-2006 04:48 AM
file transposing mskcc Shell Programming and Scripting 24 08-04-2005 11:23 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 05-11-2004
myscsa2004 myscsa2004 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 11
transposing letters

Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with:

for n in "${array[@]}"; do
echo $n
done

I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is:

aabbcc
ddeeff
gghhii

ex...if I input 'aabbcc ddeeff gghhii' into the array, is it possible to transpose them and output:

ccbbaa
ffeedd
iihhgg

can i use sed?

thanks.
  #2 (permalink)  
Old 05-11-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Perhaps use "rev"
  #3 (permalink)  
Old 05-12-2004
myscsa2004 myscsa2004 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 11
I would use rev, but i don't want to reverse the whole string...

say the input is xxyyzz, i want to keep 3 pairs of 2, and swap the xx and the zz, keep the yy in the same place, and keep the characters in the same order within their pairs...another example, say i have 123456, it would be output as 563412.

thanks.
  #4 (permalink)  
Old 05-12-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Then perhaps you agree that your example data could have been clearer! You could use awk...

$ echo 123456| awk '{for(x=1;x<=length;x+=2)s=substr($0,x,2) s}END{print s}'
563412
  #5 (permalink)  
Old 05-12-2004
myscsa2004 myscsa2004 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 11
Ygor-

my appologies on the example then, i realized that you could use rev on aabbcc after you said it

that works great, thank you so much!
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 07:38 PM.


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