Visit Our UNIX and Linux User Community


string revering fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting string revering fails
# 1  
Old 08-28-2009
string revering fails

Consider the following code
Code:
#!\bib\bash

echo -n "Enter string : "
read str
l=`expr length "$str"`
while [ "$l" -gt 0 ]
do
    echo -e `echo $str | cut -c"$l"`"\c"
        l=`expr "$l" - 1`
done
echo

the above code works perfect for string with no space in between. but fails when there is a space.
Quote:
asit@asit-desktop:~/script$ source strrev.sh
Enter string : asit
tisa
asit@asit-desktop:~/script$ source strrev.sh
Enter string : asit india
aidnitisa
How can this be done ???
# 2  
Old 08-28-2009
Maybe this is an acceptable alternative:
Code:
echo "asit india"| rev
aidni tisa

# 3  
Old 08-28-2009
I want to do this using shell scripting

Previous Thread | Next Thread
Test Your Knowledge in Computers #559
Difficulty: Easy
A runtime error is an error that occurs while a program is being executed.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Python fails to detect String Match Found

Below is my code for comparing string for Exact Match found in python. for word in jdbc_trgt.split(','): global comp comp=word.strip(); print "GloBAL:" + comp fiIn = open('list.txt').readlines() for lines in fiIn: print "line1s:" +... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

until loop fails.

i have a script like below, i am trying to print "...." until a background process that was executed before is running,, the below does work and teh loop keeps on printing "..", can someone help where i am wrong. /tmp/test/abc.sh & until do echo "..\c" done abc.sh is the scipt... (8 Replies)
Discussion started by: yesmani
8 Replies

5. UNIX for Advanced & Expert Users

why script fails sometime?

Hi, I am trying to run a shell script on solaris,some time it works fine and some times it fails unexpectedly. There is a script called "autostart.sh" which automatically starts the Application server but some times the script fails to strat the application server. can anyone tell me what... (10 Replies)
Discussion started by: tahir23
10 Replies

6. UNIX for Dummies Questions & Answers

search excat string in another string (grep "fails")

hello, i have an statement which i have to correct because it shows the wrong result. i want to search an excat string in another string, command "grep" shows the wrong result: example: STRINGS="string1 string2 string3" search_string="string" incorrect: if then echo "not... (0 Replies)
Discussion started by: bora99
0 Replies

7. UNIX for Advanced & Expert Users

make fails...

Hi When im trying to do make --version and make --help in HP-UX it throws error Make: Unknown flag argument -. Stop. a soft link is present in this directory /usr/bin/make and hard link is in /usr/ccs/bin/make what could be the reason can any1 ..please tell me how to solve this... (1 Reply)
Discussion started by: vasanthan
1 Replies

8. Shell Programming and Scripting

fgrep fails...!?

Hi all, I need to transport a number of files from one server to other. I like to ensure the integrity using file checksum values. The action plan is, 1. create the list of checksum values for all the files using cksum command in source server. 2. Transfer all the files including the file... (5 Replies)
Discussion started by: r_sethu
5 Replies

9. AIX

SCP fails sometimes

Hi, I got a unix script which copies a file from my AIX machine to a file server using SCP command. I am calling this script 3 times in my process after a time interval say 5mins. My issue here is like most of the time its not sending the file at the first time run while other 2 will work fine.... (10 Replies)
Discussion started by: vipinc
10 Replies

10. Shell Programming and Scripting

Need to know why Perl fails.

Hello . Would really like to know why this code fails . I need to edit both the QUESNO : and <\p> tag at the same time . open(TEXT, "<20030211.txt") || die ("Cannot open the text files"); while (<TEXT>) { if ($_ =~ m/QUESNO :/) { if ($_ =~ m/<\/p>/) { print ($_); ... (0 Replies)
Discussion started by: whatsup
0 Replies

Featured Tech Videos