Help with convert string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with convert string
# 1  
Old 06-20-2011
Help with convert string

Hi.
I will be very appreciated for help.
I need replace all characters into string with \ (backslash)
I mean if I have word abcdefg as input.
How I can convert it to \a\b\c\d\e\f\g

Thanks and best regards. Staas.
# 2  
Old 06-20-2011
Code:
echo "abcdefg" | sed 's/./\\\0/g'

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 06-20-2011
Code:
sed 's/./&\\/g' file

# 4  
Old 06-20-2011
Hi
Thanks for quick answer
Staas.
# 5  
Old 06-20-2011
Quote:
Originally Posted by bartus11
Code:
echo "abcdefg" | sed 's/./\\\0/g'

With the command above I get this as output:
Code:
echo "abcdefg" | sed 's/./\\\0/g'
\0\0\0\0\0\0\0

# 6  
Old 06-20-2011
Quote:
Originally Posted by Franklin52
With the command above I get this as output:
Code:
echo "abcdefg" | sed 's/./\\\0/g'
\0\0\0\0\0\0\0

Hmmm.. I guess \0 as substitute of "&" can be used only in GNU sed...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a String to a Number

I read in two numbers from a user but the number is a string. #!/bin/bash read -p "Enter first number: " num1 read -p "Enter second number: " num2 I know you can use the the "expr" or "bc" command to automatically convert the string to a number then add them together. But I don't want to add... (10 Replies)
Discussion started by: Loc
10 Replies

2. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

3. Shell Programming and Scripting

Convert string using sed

I have a couple structure definitions in my input code. For example: struct node { int val; struct node *next; }; or typedef struct { int numer; int denom; } Rational; I used the following line to convert them into one line and copy it twice. sed '/struct*{/{:l... (3 Replies)
Discussion started by: James Denton
3 Replies

4. Shell Programming and Scripting

Convert string in a column

Hi I got this: aix.acct,aix.system.config.cron,aix.system.config.src,aix.system.install,string2 and I want this: aix.acct system.config.cron aix.system.config.src aix.system.install string2 I tried using sed by changing ',' into an 'ENTER' but I couldn't. :-( thxs (2 Replies)
Discussion started by: iga3725
2 Replies

5. Shell Programming and Scripting

Convert output to string

Hi Guys, is there any command to convert the output returned by the below command to string format: Code: sed 1!d filename Output is : 108 ---------- Post updated at 11:03 AM ---------- Previous update was at 11:00 AM ---------- Because i am using this output as string parameter ... (4 Replies)
Discussion started by: kam786sim
4 Replies

6. UNIX for Dummies Questions & Answers

Convert string to uppercase

i have this piece of small code that checks for *.CSV files. NUMFILES=`ls -1 *.CSV | wc -l` for filename in $(ls -1 *.CSV) do ... done it works only if the files has an uppercase of *.CSV extension. however, when there is a file of the same type but has lowercase *.csv... (1 Reply)
Discussion started by: wtolentino
1 Replies

7. Shell Programming and Scripting

how to convert array into the string

Hi I have a line/string as follows: A=" 3498 NORDEA - INDX LINKED NORY" which was converted into an array of characters: p321$ echo "${ARR}" 3 4 9 8 N O R D E A - I N D X L I N K E D N O R Y When I am trying print this array there are blank... (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

Convert String to Date

Hi, I have a String input parameter like this: 20080430 (YYYYMMDD). Inside my korn shell script I need to add one day to this date. L_TRADE_DAY=$1 let L_TODAY=$L_TRADE_DAY+1 Offcourse this raises a problem at the end of a month. 20080430 + 1 gives 20080431 instead of 20080501. ... (2 Replies)
Discussion started by: ORatjeuh
2 Replies

9. Shell Programming and Scripting

how to convert a string to int

Hi, i want to read a text file whose content(single line) will be a number like 1 or 2 or 3 ..... what i want to do is to read the file and increment the content of the file, using unix scripting. Regards, Senthil Kumar Siddhan. (2 Replies)
Discussion started by: senthilk615
2 Replies

10. UNIX for Dummies Questions & Answers

convert from an integer to a string

i want to convert from an integer to a string..in unix...i am writing a C program with embedded SQL... I remeber using itoa...but for some reason it doesnt work......i cant find it in the manual..... Maybe that is the wrong command..... but i have checked Dev Studio.....and it doest exist in the... (6 Replies)
Discussion started by: mojomonkeyhelper
6 Replies
Login or Register to Ask a Question