echo omits slash - how to avoid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo omits slash - how to avoid
# 1  
Old 02-21-2006
Data echo omits slash - how to avoid

Hi,

I have a file which contains as follows,

a.tmp
Test \13\
Hello

When i read the file and print the ouput using echo, "\" is not coming. How to avoid it.

here goes the script
a.sh
-----
while read line
do
echo $line
done < a.tmp

Output is:
Test 13
Hello

I need "\" to appear in the output.

Any ideas, please help.

Thanks,
Om
# 2  
Old 02-21-2006
MySQL

here goes the solution,

read -r <line> will not take the backslash character in account.

cheers,
om
# 3  
Old 02-21-2006
Or you could use a backslash to escape your backslash, like this

Test \\13\\

Or you could put quotes around that line to get it to ignore the backslashes.
# 4  
Old 03-21-2006
Incorrect output from script

To have the script include the "\" character I would re-write it so that the condition echo $line is replaced by echo "\$line\". In this way the reverse virgules should appear on either side of the line number.

Good luck!
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to remove slash

I got stuck in problem i need to remove slash but it is not working. current output /usr/sbin/httpd expected output usr sbin httpd (4 Replies)
Discussion started by: learnbash
4 Replies

2. Shell Programming and Scripting

Slash delimiter

I have a log file which on field $11 there is sth like: /A/B/C and I want to extract the last part which is C. for space delimiter I used: awk '{print $2 " " $5 ";" $7 ";" $9 ";" $11}' and had no problem. but dont know how to extract the 3rd part of the slash delimiter. That would be... (6 Replies)
Discussion started by: frhling
6 Replies

3. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

4. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

5. UNIX for Advanced & Expert Users

Substitute single backward-slash with the double backward-slash

Hi, I have a path like this c:\test\sample\programs, i need to change thiis to c:\\test\\sample\\programs. How to perform this? I tried tr command but it didn't help me. Thanks Vijayan (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

6. Shell Programming and Scripting

About \ (Back slash)

Hi All, print "path/executable_file parameters" \ > path/file1 print "path/executable_file parameters" \ > path/file2 print "path/executable_file parameters" \ > path/file3 chmod 775 path/file1 \ path/file2 \ ... (7 Replies)
Discussion started by: Arunprasad
7 Replies

7. Shell Programming and Scripting

escaping / (forward slash)

how to escape / (forward slash) in a string. I have following scnerio: sed s/${var1}{$var2} var1 and var2 both contain slashes, but sed gives error if there is a slash in var1 or var2. sed is used here to replace var1 with var2. Thanks in advance (1 Reply)
Discussion started by: farooqpervaiz
1 Replies

8. Shell Programming and Scripting

Replace the last slash alone

Hi All, Can you please help me with the below issue. I want only the last slash to be replaced with space. 06/05/2008/EDED_FD_BDCD_ABCD_123 06/05/2008 EDED_FD_BDCD_ABCD_123 (3 Replies)
Discussion started by: christineida
3 Replies

9. UNIX for Dummies Questions & Answers

echo is suppressing multiple spaces.How to avoid it

I am reading a file and copying selected lines from the file into another using echo. For eg: while read line do if ((some logic to determine whether I need to copy the current line to another file)) then echo $line > tempfile fi done<srcfile The problem I have is the data in the file... (1 Reply)
Discussion started by: prathima
1 Replies

10. Shell Programming and Scripting

awk slash

I have configuration file(master.cnf), that contents are: VER1LOG /src/ver1/log VER2LOG /src/ver2/log APPLOG /src/sys/apps/log APPCONF /src/sys/apps/conf APPBIN /src/sys/apps/bin my shell script is as below mylog=sys/apps awk "/$mylog/" master.cnf awk: syntax error Context is: >>> ... (6 Replies)
Discussion started by: McLan
6 Replies
Login or Register to Ask a Question