How can I match . (actual dot) using sed?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can I match . (actual dot) using sed?
# 1  
Old 09-19-2005
How can I match . (actual dot) using sed?

Hi All,
How can I match . (actual dot) using sed? Please help.

Thanks
# 2  
Old 09-19-2005
You need to escape it with a \

Look at this.

Code:
sh-2.05b$ cat jing.txt
test
.
test.match

Code:
sh-2.05b$ sed -n -e '/\./p' jing.txt
.
test.match

# 3  
Old 09-19-2005
Thanks vino.

But this doesn't work. I am looking for /./* (one or more of /./ and replace with a single /./

I tried dereferencing . and /
it doen't work. Please help.

Thanks
# 4  
Old 09-19-2005
This is going to be a confusing regex.

Code:
sed -e 's#\/\.\/\{1,\}#\/\.\/#g'

vino
# 5  
Old 09-19-2005
Please see below:

cat 1 gives:

Code:
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./

Code:
sed -e 's#\.\{1,\}#\.#g' 1 > 2

now see cat 2

Code:
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./

It is not working.

Last edited by rbatte1; 01-13-2017 at 07:17 AM.. Reason: Added CODE tags
# 6  
Old 09-19-2005
Yes the previous solution will not work.

But this should work

Code:
sh-2.05b$ cat jing.txt 
test
/./
test/.//.//./match
sh-2.05b$ sed  -e 's#\(\/\.\/\)*#\1#g' jing.txt 
test
/./
test/./match

vino
# 7  
Old 09-19-2005
Code:
cat 1
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./

Code:
sed  -e 's#\(\/\.\/\)*#\1#g' 1 > 2

Code:
cat 2
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./
/.//.//./

It is not working. Is there is special reason why this doesn't work?

Last edited by rbatte1; 01-13-2017 at 07:17 AM.. Reason: Added CODE tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting out of sed on first NOT match

i have a large file where i want to look for any record that is is larger or smaller than 21 and if it is the case i want to report and break SED .. how can i achieve it ? i dont want sed to scan the complete file after one non match is found. (4 Replies)
Discussion started by: boncuk
4 Replies

2. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies

3. Shell Programming and Scripting

sed match

Hi can anyone help with the following: echo "Date range on 5th May is between -010516 and 050516- please continue "| sed 's/\(.*-\)\(.*-\)\(.*$\)/\2/' output 010516 and 050516- What i need is to include the - to be included. Desired output: -010516 and 050516- I know... (11 Replies)
Discussion started by: andy391791
11 Replies

4. Shell Programming and Scripting

sed - search and replace whole string which contains dot

Hello. I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3" And I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3" And I would not found in the result : "string1.new_string2.new_string3"... (3 Replies)
Discussion started by: jcdole
3 Replies

5. UNIX for Dummies Questions & Answers

sed Exact Match when Dot is present

I am trying to replace exact word from my text. I know using the angled brackets does the trick. But it is not working when there is a dot in the text. echo "Bottle BottleWater Bottle Can" | sed 's/\<Bottle\>//g' BottleWater CanBut if my data has a dot or hash in it, it replaces all the... (10 Replies)
Discussion started by: grep_me
10 Replies

6. Shell Programming and Scripting

Awk/sed - add space between dot and letter

I need to change . into . so that e.g. A.Jbecomes A. JI have tried sed 's/\./\.\ /g' but that didn't work. (9 Replies)
Discussion started by: locoroco
9 Replies

7. Shell Programming and Scripting

how to remove a variable starting with dot using sed command

Hi, I want to remove a variable starting with dot(.) in a file using sed command. aaa sss .abc s/^\.abc/d I tried this but it didnt worked. (5 Replies)
Discussion started by: vdhingra123
5 Replies

8. Shell Programming and Scripting

Regular Expression doesn't match dot "." in a string

hello, I am writting a regular expression that intend to match any tunnel or serial interface but it doesn't mtach any serial sub-interface. For example, statement should match "Tunnel3" or "Serial0/1" but shouldn't match "Serial0\1.1" (doesn't include dot ".") I tried the following but... (3 Replies)
Discussion started by: ahmed_zaher
3 Replies

9. UNIX for Dummies Questions & Answers

sed can't match '\n' ?!

Hi: it seems very strange. there is a file with multiple lines. After I squeezed out the consecutive blank lines (and some other text processing), somehow the sed '/\n/! d' file can not generate any output, as if it can't find any line with newline. the file is has many lines, so... (9 Replies)
Discussion started by: phil518
9 Replies

10. Shell Programming and Scripting

how do I negate a sed match

I have a text file that has links in it. I can write a match for sed to replace the link with anything. For example: http://www.google.com becomes XxX But what I'm after is not to replace the link with something but to remove everything else and just leave the link. I want a... (5 Replies)
Discussion started by: muxman
5 Replies
Login or Register to Ask a Question