Remove path string from file (string contains "/")


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove path string from file (string contains "/")
# 1  
Old 08-30-2010
Question Remove path string from file (string contains "/")

This is the way
Code:
sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc

But, as far as I saw you cannot add any "/" in the string you want to remove....
So, what should I do in order to remove this path (which contains "/") ?Smilie
# 2  
Old 08-30-2010
Code:
sed -i 's#home/$USER/.config/hello_there##g' /home/$USER/.gnomerc

# 3  
Old 08-30-2010
Amm, thanks, this worked supposing you know the name of the Variable $USER....
e.g.
sed -i 's#home/alex/.config/hello_there##g' /home/$USER/.gnomerc #WORKS
sed -i 's#home/$USER/.config/hello_there##g' /home/$USER/.gnomerc #DOESN'T WORK
# 4  
Old 08-30-2010
Code:
sed -i "s#home/$USER/.config/hello_there##g" /home/$USER/.gnomerc

Always solving one problem at a time Smilie
This User Gave Thanks to bartus11 For This Post:
# 5  
Old 08-30-2010
Quote:
Originally Posted by bartus11
Code:
sed -i 's#home/$USER/.config/hello_there##g' /home/$USER/.gnomerc

Use double quotes Smilie:
Code:
sed -i "s#home/$USER/.config/hello_there##g" /home/$USER/.gnomerc

This User Gave Thanks to Franklin52 For This Post:
# 6  
Old 08-30-2010
Thank you all.
# 7  
Old 08-30-2010
Code:
# sed -i 's/home\/'$USER'\/.config\/hello_there//g' /home/$USER/.gnomerc

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

2. Shell Programming and Scripting

Remove leading "#" from a String

Hi Everyone, i am new to scripting and stuck in something. Query is : I have a properties file eg. data.properties. This data.properties have some values example : key1=value1 key2=value2 #key3=value3 as key3 is commented by #. so i want to write a script , that will remove # from... (3 Replies)
Discussion started by: Raj87ng
3 Replies

3. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

4. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

5. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

6. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

7. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

8. Shell Programming and Scripting

grep for string "and" string in a file

Hi, I am trying to look for two different strings in a file using an "AND" operator. For instance... File 1.txt woof meow File 2.txt woof bark I want to do a search in the directory to give me the name of the file that contains both "woof" and "meow" on different lines. So in this... (2 Replies)
Discussion started by: jdc25180
2 Replies

9. Shell Programming and Scripting

input string="3MMTQSZ348GGMZRQWMJM4SD6M";output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6

input string="3MMTQSZ348GGMZRQWMJM4SD6M" output string="3MMTQ-SZ348-GGMZR-QWMJM-4SD6M" using linux shell script (4 Replies)
Discussion started by: pankajd
4 Replies

10. 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
Login or Register to Ask a Question