LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06: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, 06:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Have a look at this:
Code:
sed 's%/\.%%g' infile
 
1 members found this post helpful.
Old 10-05-2012, 06: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, 01:33 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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, 01: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



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 06:30 AM
[SOLVED] sed/awk : remove section from file vrusu Linux - Newbie 3 10-26-2010 08:49 AM
how to remove words in a file using sed or any other command Kilam orez Linux - Newbie 4 11-30-2009 08:52 AM
sed to remove specific lines in a file tekmann33 Linux - Newbie 3 05-21-2009 03:41 PM
Remove sections of a xml file with sed viniciusandre Linux - Software 2 04-20-2009 01:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:53 AM.

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
Open Source Consulting | Domain Registration