reading and reversing a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading and reversing a string
# 1  
Old 02-24-2009
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????
# 2  
Old 02-24-2009
here's a good place to start.
# 3  
Old 02-24-2009
Sorry to say.....But i did not understand anything from that.can u provide me anyother matter????
# 4  
Old 02-24-2009
Here's the needed extract from the same 'matter':
Code:
# reverse each character on the line (emulates "rev")
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'

Applying the 'matter' to sample "string":
Code:
$ echo 'abcd' | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
dcba

# 5  
Old 02-24-2009
what does sed do????
# 6  
Old 02-24-2009
Quote:
Originally Posted by nikhilneela
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????
This smells like a homework problem, can you explain what you're trying to achieve? What is the real world problem you're trying to solve?

Regards
# 7  
Old 02-24-2009
'man sed' yields the following:
Code:
NAME
     sed - stream editor

SYNOPSIS
     /usr/bin/sed [-n] script [file...]

     /usr/bin/sed   [-n]    [-e script]...    [-f script_file]...
     [file...]

     /usr/xpg4/bin/sed [-n] script [file...]

     /usr/xpg4/bin/sed [-n]  [-e script]...   [-f script_file]...
     [file...]

DESCRIPTION
     The sed utility is a stream editor that reads  one  or  more
     text  files,  makes editing changes according to a script of
     editing commands, and writes the results to standard output.
     The  script  is  obtained  from  either  the  script operand
     string, or a combination of the option-arguments from the -e
     script and -f script_file options.

     The sed utility is a text  editor.  It  cannot  edit  binary
     files  or files containing ASCII NUL (\0) characters or very
     long lines.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading between a repeated string

I have a requirement where I have to read the lines between a repeated string FileName: abc.txt ls /data/abc.txt 1 2 #ZENCO 3 4 5 6 #ZENCO 11 213 454 7 #ZENCO (8 Replies)
Discussion started by: eskay
8 Replies

2. Shell Programming and Scripting

Reading XML and replacing a string

Hi All, My thanks in advance for you guys reading this and for any posts. I'm having 100 XML files, I need script which replace a specific string. It must be incrementing in 100 xml files.. Sample XML files: <hwIPHostName type="attrib">DEMO1</hwIPHostName> I need Demo1 to be... (4 Replies)
Discussion started by: karty2129
4 Replies

3. Shell Programming and Scripting

File Reading for a certain string and echo the line before

Hi Guys, I have a big file like this. It has cache group line ( the bold lines ) and then followed by 10 status lines showing either Compelte or Failed. This pattern repeats several time. We can assume all the status lines have either Complete or Failed status for that Cache Group line. I... (13 Replies)
Discussion started by: MKNENI
13 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

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

6. UNIX for Dummies Questions & Answers

Reading one line from a multiline string

Hi , I have a string which is of multiple line,I have to split the string by reading one line in each iteration and keep it in a string.I am keeping all the file names in side as string returned by the ls command ,I am stocked at the point of spliting the string to segragate each file. ... (4 Replies)
Discussion started by: Deekay.p
4 Replies

7. Shell Programming and Scripting

reading a .dat file in to a string

i have folowing code. i dont want data in an array. i like to put my data file info (after filtering and converting to lower case) in to a string call "name". so it would look like this, name= ffjtgj345 thgkty3 456gfhf rhtfn4 ...... how do i do that? i dont want to read # or blank lines. ... (13 Replies)
Discussion started by: usustarr
13 Replies

8. Shell Programming and Scripting

reading a string characterwise

hi , I am trying to read two strings character by character using arrays but i couldn't do it pls.give a solution (2 Replies)
Discussion started by: akmtcs
2 Replies

9. Shell Programming and Scripting

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()? (3 Replies)
Discussion started by: ccp
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