LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2012, 05:12 AM   #1
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Rep: Reputation: Disabled
Deleting Lines Ending With a Full Stop Using SED


Hi

How do I delete a line which ends with a full-stop? Sometimes there are two or even three full stops at the end.

It is a list of e-mail addresses.

Kind Regards

ARNOLD
 
Old 07-12-2012, 05:36 AM   #2
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 70

Rep: Reputation: 18
How about something like:

Code:
grep -v '\.$' filein.txt > fileout.txt
This will search the file filein.txt and only show output for files that do not end with a . (period) and output hte results into a file called fileout.txt

although this does not use sed
 
Old 07-12-2012, 06:40 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
And of course, something very similar will work with sed.
 
Old 07-12-2012, 06:59 AM   #4
pobrika
Member
 
Registered: Jan 2008
Location: Bournemouth, UK
Distribution: Mint, #!, Fedora, Redhat, Centos
Posts: 70

Rep: Reputation: 18
If you must use sed then as syg00 said you can use sed in a similar fashion to grep -v as follows:

Code:
sed -n -e '/\.$/!p' filein.txt > fileout.txt
 
Old 07-12-2012, 07:57 AM   #5
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Original Poster
Rep: Reputation: Disabled
Hi

Both methods work. Thank you.

Can you provide an explanation about some of the arguments. What I know is that:

1. '/ /' is standard notation
2. \.$ refers to the end of the line. Why does one have to use the \ could one not just have used .$
3. filein and fileout.

What does the others mean?

sed -n -e '/\.$/!p' filein.txt > fileout.txt

Once again, thank you.

Kind Regards

ARNOLD
 
Old 07-12-2012, 07:59 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Or you could use the delete option for sed (//d)
 
Old 07-12-2012, 08:01 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
2. \.$ refers to the end of the line. Why does one have to use the \ could one not just have used .$
A period matches any character so to refer to a period you need to escape it or place it in a character class ([])
 
  


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
deleting duplicate lines without deleting first instance of the duplicated line jkeertir Linux - Newbie 2 02-07-2011 06:55 AM
[SOLVED] How to remove line breaks from lines ending with a comma jasonws Linux - General 1 11-10-2010 12:03 PM
Sed command to print matching lines and 2 lines above.. DX398 Programming 12 10-01-2008 08:25 AM
Probably a simple sed questions for deleting lines... oldcarguy85 Linux - General 4 03-28-2008 07:11 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:22 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
Open Source Consulting | Domain Registration