LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2012, 07:15 AM   #1
jta_val
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Rep: Reputation: Disabled
remove /. from file with sed


Hi!

I've got a file like this:

scaffold_1 3151 C/T C/. C/.
scaffold_1 3169 T/G T/. T/.
scaffold_1 3170 A/G A/. A/.
scaffold_1 3173 G/A G/. G/.
scaffold_1 3303 T/A T/. T/.
scaffold_1 3309 A/C A/. A/.
scaffold_1 3311 A/G A/. A/.
scaffold_1 3326 T/A T/. T/.
scaffold_1 3341 T/G T/. T/.
scaffold_1 4108 A/. A/G A/.
scaffold_1 4131 A/. A/G A/.

I would like to remove all the /. and leave de letters alone. I managed to remove . or / with sed, but not both of them. Can you help me. I need to keep the slash between two letters, just want to remove /.

Thanks a lot in advance!
 
Old 10-05-2012, 07:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Have a look at this:
Code:
sed 's%/\.%%g' infile
 
1 members found this post helpful.
Old 10-05-2012, 07:56 AM   #3
jta_val
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
It worked!

Thanks a lot!
 
Old 10-07-2012, 02:33 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Just to make it perfectly clear, there are two issues involved here.

1) The "/" conflicts with sed's traditional 's' command separator. Solution: use another separator. sed can use any basic ascii character, so just choose one that's not found in the string. Good ones to use are often ^, #, @, _, and |.

You could also simply backslash escape it if you wanted, but that tends to be less readable.

2) "." is the regular expressions operator for matching "any single character". So "/." in your expression would also match, for example, "/A". Solution: either backslash escape the dot, or confine it within a regex bracket expression "[.]".
 
Old 10-08-2012, 02:39 AM   #5
jta_val
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you very much, now I know why id did not work!

Javier
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed used to remove a line from xml file nano2 Linux - General 6 10-25-2011 07:30 AM
[SOLVED] sed/awk : remove section from file vrusu Linux - Newbie 3 10-26-2010 09:49 AM
how to remove words in a file using sed or any other command Kilam orez Linux - Newbie 4 11-30-2009 09:52 AM
sed to remove specific lines in a file tekmann33 Linux - Newbie 3 05-21-2009 04:41 PM
Remove sections of a xml file with sed viniciusandre Linux - Software 2 04-20-2009 02:18 PM


All times are GMT -5. The time now is 08:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration