Sed: removes \ from text which causes issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed: removes \ from text which causes issues
# 1  
Old 04-23-2013
Sed: removes \ from text which causes issues

Hi all,

Hoping someone hoping someone might be able to help. i've got the following sed command which i'm using in a bash script that i'm trying to use to insert a new line into an already existing file so i don't have to manually enter it when setting stuff up. the existing script test2/3 are just scripts to move files/ folders etc.

Code:
sed "113a\mv -v $DISK2/$SHOW\ folder2 $DISK/$SHOW/$FOLDER1" test3.sh > test2.sh

The problem i am having is that when the script resolves the first $SHOW it removes the "\" that is right after it which is used to show its a name with a space within the command line.

expected outcome:
Code:
mv -v /disk/disk2/Test\ folder2 /disk/disk1/Test/folder

actual outcome:
Code:
mv -v /disk/disk2/Test folder2 /disk/disk1/Test/folder

is there a way for sed to leave the "\" alone so it won't effect my script?

Also, if $SHOW has a space in the name is there a way to either put a "\" in so it will work or another way that it won't cause that mv command to fail.
# 2  
Old 04-23-2013
Code:
$ echo xx | sed "1a\mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW folder2 DISK/SHOW/FOLDER1

Code:
$ echo xx | sed "1a\mv -v DISK2/SHOW\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW folder2 DISK/SHOW/FOLDER1

Code:
$ echo xx | sed "1a\mv -v DISK2/SHOW\\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1

Code:
$ echo xx | sed "1a\mv -v DISK2/SHOW\\\\ folder2 DISK/SHOW/FOLDER1"
xx
mv -v DISK2/SHOW\ folder2 DISK/SHOW/FOLDER1

# 3  
Old 04-23-2013
Thanks,

I put a tripple \ in the command and it worked.

any idea if its possible as well with the 2nd part of the question? if $SHOW contains a space in the name if its possible to put the space in it?
# 4  
Old 04-23-2013
I would try the following, putting escaped "double quotes" around the SHOW variable. I cannot guarantee it will work, as the testing is a bit awkward, but I think a good chance it will work:
Code:
sed "113a\mv -v $DISK2/\"$SHOW\"\\\ folder2 $DISK/\"$SHOW\"/$FOLDER1" test3.sh > test2.sh

If possible to remove those blanks from files names, I would encourage that. Those blanks in file names cause so many irritations. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk removes attachment in email

Hi We have a requirement to send email using shell script.email should have html body and pdf attachment. We used uuencode for attaching files and sendmail option to acheive and it is working fine. However custoemr wants to make body of email slightly dynamic. E.g dear customer in html file... (3 Replies)
Discussion started by: Harish7586
3 Replies

2. Shell Programming and Scripting

Issues with using sed with word delimiters \< and \>

sed is not applying /d "delete line" option when I also include match word options \< and \> examples... echo cat | sed '/\<cat\>/d' will return cat for some reason echo cat | sed "/\<cat\>/d" will also still return cat. Of course I can just run this... echo cat | sed '/cat/d' and... (1 Reply)
Discussion started by: escooter87
1 Replies

3. Shell Programming and Scripting

Issues in sed command

I use SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux We have a user-defined command called "submit" which will open a vi terminal in which we need to enter the description at 24th line and save it. In order to simplify this, i decided to create another command in which the... (3 Replies)
Discussion started by: pandeesh
3 Replies

4. Shell Programming and Scripting

Issues with sed on SunOS

Why does the below command doesnt work fine on SunOS 5.10 $ cat t | AK| | | | | DS | | | | tAR | | | | | FIL | $ sed -e 's/^ *//g' -e 's/ *$//g' -e 's/ *| */|/g' t |AK|||||DS|||| tAR|||||FIL| ##notice before tAR works fine on Linux OR AIX though ... (8 Replies)
Discussion started by: Shivdatta
8 Replies

5. UNIX for Advanced & Expert Users

perl/sed -i removes link

hello, is it a behavior of or that "-i" removes unix link . example : i create a file "src_file" and link it to "link_file" and then i start "perl -i" the link is removed. does another option exists to change content of a file without temporary files ? UNIX-Version: HP-UX and... (2 Replies)
Discussion started by: bora99
2 Replies

6. UNIX for Dummies Questions & Answers

Sed to remove only first line erroneously removes last line too

Hello everyone, This is my first posting. I have read the rules of this forum. I have searched many various threads and haven't found one that applies to my situation or suggestions to fix the issue. I do appreciate the help. I am trying to execute a basic UNIX script in a Solaris... (4 Replies)
Discussion started by: dqrgk0
4 Replies

7. Shell Programming and Scripting

sed command removes lines in file

Hi, I am modifying a file with sed command. i want to make SCORE= blank in the file whereever SCORE=somevalue. What will *$ do in the below command? cat $file | sed 's/SCORE=.*$/SCORE=\r/g' > newfile The last line is also missing in the new file. How to make SCORE='100' to SCORE=... (5 Replies)
Discussion started by: ashok.k
5 Replies

8. Shell Programming and Scripting

sed edit in place -i issues

Hello, I am attempting to create a command that I can eventually put into a loop so I can edit 1file on many servers. I would like to edit the file in place with sed -i. If not I will take any suggestions on how to use a temp file. I need to remove a email address from the configuration file... (4 Replies)
Discussion started by: abacus
4 Replies

9. Shell Programming and Scripting

sed issues

Hi guys, not that used to using sed beyond the simple substitution. I am trying to check for a program (program1) and if it exists replace the standard output "program1" with a "program1(part1 part2) output if said program exists. SW="program1 program2" PROGRAM_TEST='echo "$SW" | grep... (3 Replies)
Discussion started by: mikepegg
3 Replies

10. Linux

Plain Text printing issues

I'm attempting to print to a networked konica printer. No linux drivers that I know of exist, but we've always used HP 5si drivers and have had good results. We just loaded a box up with CentOS 5, and now when we print any sort of file from the command line (lp -dkonica <filename>), the text is... (0 Replies)
Discussion started by: fender177
0 Replies
Login or Register to Ask a Question