[Solved] Disappearing backslash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Disappearing backslash
# 1  
Old 01-15-2014
[Solved] Disappearing backslash

Let's say I have a text file called process.out that contains:
Code:
cn=long\, ann,cn=users
cn=doe\, john,cn=users

I need to have the following appended in the beginning
Code:
ldapdelete -h $OIDHOST

So the final output looks like:
Code:
ldapdelete -h $OIDHOST "cn=long\, ann,cn=users"
ldapdelete -h $OIDHOST "cn=doe\, john,cn=users"

The problem is that I need the 'backslash' in the command and whatever I try, it gets filtered out. I tried this:

Code:
cat process.out  | while read CMD; do echo ldapdelete -h $OIDHOST \"$CMD\"; done

Which results in:
Code:
ldapdelete -h $OIDHOST "cn=long, ann,cn=users"
ldapdelete -h $OIDHOST "cn=doe, john,cn=users"

Any thoughts?

Last edited by Scrutinizer; 01-16-2014 at 01:37 PM..
# 2  
Old 01-15-2014
That is a useless use of cat.

That aside, read is eating your backslashes here. By default it tries to interpret them. Use read -r to avoid that problem:

Code:
while read -r CMD
do
        echo ldapdelete -h $OIDHOST \"$CMD\"
done < inputfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-15-2014
As always, in command arguments put $var in quotes!
Code:
while read -r CMD
do
        echo ldapdelete -h "$OIDHOST" \""$CMD"\"
done < inputfile

Special characters like backslash are preserved.

Last edited by MadeInGermany; 01-17-2014 at 02:37 PM.. Reason: (last line was joined to prev line)
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 01-15-2014
Hello,

Following may help too.

Code:
awk -vs1="ldapdelete -h $OIDHOST" -vs2="\"" '{print s1" "s2$0s2}' file_name

Output will be as follows.


Code:
ldapdelete -h  "cn=long\, ann,cn=users"
ldapdelete -h  "cn=doe\, john,cn=users"


Thanks,
R. Singh
# 5  
Old 01-16-2014
Thanks all! You have been very helpful as usual!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Groups are disappearing on opening of new konsole/terminal

Hi when I open a new KDE/terminal all my project groups are disappearing. help is much appreciated. Thanks Sujay (2 Replies)
Discussion started by: sujaybatni
2 Replies

2. Shell Programming and Scripting

Replace semicolons with tabulators, new lines are disappearing

Hi Gurus! Example file: 1;AAA;BBB 2;CCC;DDD We want to replace semicolons to tabulators. Like this: 1 AAA BBB 2 CCC DDD We have tried these codes. With PERL: #!/bin/bash for i in `find /folder1/ -name "*.CSV"` do bi="`basename $i awk -F"." {'print $1'}`" cat... (2 Replies)
Discussion started by: JanneN
2 Replies

3. Solaris

Crontab latest entry disappearing. plz help

The latest crontab entry is disappearing time and again on acceptance and production environment. the same entry gets deleted. any pointers to what might be causing this issue? (6 Replies)
Discussion started by: bluenavi
6 Replies

4. Solaris

Crontab latest entry disappearing

The latest crontab entry is disappearing time and again on acceptance and production environment. the same entry gets deleted. any pointers to what might be causing this issue? (1 Reply)
Discussion started by: bluenavi
1 Replies

5. UNIX for Advanced & Expert Users

Files disappearing from /users/home

We have seen an issue whereby every morning around the same time , we see files being deleted from /users/$userid . We have many crons and processes running across 40+ different servers . Possibly some rogue process is doing this . How can one isolate the process removing stuff from the... (4 Replies)
Discussion started by: taherkf
4 Replies

6. Windows & DOS: Issues & Discussions

Disappearing wget download [Windows]

I downloaded and installed wget for windows, then used cmd.exe to run it directly from its install folder. I downloaded an 8.5 GB (yes, Giga) tar file, waited a couple of days, then tried to find it only to see that it's nowhere to be found! I don't want to re-download the whole thing, especially... (3 Replies)
Discussion started by: HalfThere
3 Replies

7. UNIX for Dummies Questions & Answers

Escaping backslash

I have a variable containt something like this, c:\mask\mask. How can I escape "\" in the values? I want the value as it it. (9 Replies)
Discussion started by: swmk
9 Replies

8. UNIX for Dummies Questions & Answers

Disappearing files

Suse 10.3 ispconfig Using as a web server, mail server. I'm the only user. These files: /var/log/httpd/ispconfig_access_log_2008_08_28 /var/log/httpd/ispconfig_access_log_2008_08_29 vanished without a trace. I still have older and newer files, but not these. I have not deleted... (5 Replies)
Discussion started by: KillerDog
5 Replies

9. UNIX for Dummies Questions & Answers

Disappearing route

I have a route that disappears when the server is rebooted. to get the route back I do: route add 65.x.x.x 10.0.x.x I go to cd /etc/inet vi config and the route is in place Anybody might know what is happening? (4 Replies)
Discussion started by: jrmontg
4 Replies

10. UNIX for Dummies Questions & Answers

backslash issues

Hi, I have a script which looks through an input file and takes data from the file to use within the script. Everything works fine until the script reads the item \windows\directory\structure\ from the input file into a variable. As unix sees the backslash as an escape character, the... (5 Replies)
Discussion started by: Bab00shka
5 Replies
Login or Register to Ask a Question