output string in reversing order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output string in reversing order
# 1  
Old 11-18-2005
output string in reversing order

If I have string { I_love_shell_scripts}
anyone knows how to have output {stpircs_llehs_evol_I}
by using shell and perl ?I know in perl, there is reverse() funcation, but
can it be done by not using reverse()?
# 2  
Old 11-19-2005
Looks like homework. Is it? May be you should solve this one on your own.
# 3  
Old 11-19-2005
this had been already posted

you should have tried with the search option

here is the link

could u please make a try!!!

reversing a string
# 4  
Old 11-19-2005
Quote:
Originally Posted by ccp
I know in perl, there is reverse() funcation, but
can it be done by not using reverse()?
Of course yes. This is simple enough. Are you ready to try it on your own?

My implementation is a subroutine that contains only 3 statements using a recursive scheme. This is one way.

Another way: you can always find the length() of the string, so you know the largest character position is 1 less than that value, then write a loop to read each character backwards with substr().
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Why does output order change?

I have this END section in an awk script: END { for (j in littlebin) { print (j, int(log(j)/log(2)) , littlebin) lbsum+=littlebin } for (i in bins) ... (6 Replies)
Discussion started by: treesloth
6 Replies

2. Shell Programming and Scripting

Reversing text order of each line of a file in UNIX

My input is: hello how are you my chemistry book is lost what is up etc... And I want the output to be: you are how hello lost is book chemistry my up is what .... I found an earlier response to a similar question but it was not accurate as it required a certain string length for each line (2 Replies)
Discussion started by: Heidi Heweidy
2 Replies

3. Shell Programming and Scripting

egrep output order

The order of egrep output seems to be as they occur in the file. How do I get the order as requested? For e.g. file contents: AAA EEE GGG egrep 'GGG|AAA|EEE' file gives AAA EEE GGG instead of GGG AAA EEE (2 Replies)
Discussion started by: madhavb
2 Replies

4. Programming

Some error with number of keyboard inputs occured with this code for reversing a string..

i used a two-way linked list "node" for the code:: #include<stdio.h> #include<malloc.h> void insert(); void reverse(); struct node { char c; struct node *next; struct node *back; }*start=NULL; int main() { int n,i; (4 Replies)
Discussion started by: mscoder
4 Replies

5. UNIX for Dummies Questions & Answers

Reversing line and word order using awk

Hello, I am new to awk and I was wandering if I could reverse line and word order from a text file using awk. I figured out how to do them both separately, but can't quite figure out how to mix them. Example: Input file: dog cat mouse 1 2 3 I am new to awk Output of the awk program:... (3 Replies)
Discussion started by: blink_w
3 Replies

6. UNIX for Dummies Questions & Answers

Newbie Alert:Reversing part of a string?

Hello all, Wondering if anyone can help me out. Trying to cut the names out of the /etc/passwd file so that they can be displayed first then last name. I cut them out and put them into variables but cant get them to display side by side after cutting. Anyone able to help a newbie? (1 Reply)
Discussion started by: losingit
1 Replies

7. Shell Programming and Scripting

reversing order of lines in a file

how can i reverse the line order in text files? (but total number of the lines is not constant ) for example i have a file like this: line1 line2 line3 . . lineN i wantto make it like this: lineN . . . line3 (26 Replies)
Discussion started by: gfhgfnhhn
26 Replies

8. Shell Programming and Scripting

reading and reversing a string

Hi Everyone....I am new to Unix and BASH programming...I just want to read a string and reverse it and display.....can anyone help me out???? (8 Replies)
Discussion started by: nikhilneela
8 Replies

9. Shell Programming and Scripting

Reversing file order using SED

Im trying to develop a shell script that will change the content order of the file. For example I have a file that says a b c d I want to change this to be d c b a Im trying to use sed to this by reading the file and then inserting each line at the top #!/usr/bin/ksh ... (3 Replies)
Discussion started by: MBGPS
3 Replies

10. Shell Programming and Scripting

Reversing and trim a String through SHELL script

All I want to reverse and trim a string using UNIX shell scripts.Iam using Bourne shells. Can you help me? Thanx in advance Regards Deepak (5 Replies)
Discussion started by: DeepakXavier
5 Replies
Login or Register to Ask a Question