LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-02-2013, 02:08 AM   #1
georgi
LQ Newbie
 
Registered: Apr 2012
Location: Bulgaria
Distribution: openSuSE
Posts: 15

Rep: Reputation: Disabled
Delete lines from a text file not starting with "http://" or "https://"


Hi,

could someone, please, help me how to delete all lines in a text file that start with something different than "http://" or "https://".

Any help is greatly appreciated.
 
Old 10-02-2013, 02:43 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
Quote:
Originally Posted by georgi View Post
could someone, please, help me how to delete all lines in a text file that start with something different than "http://" or "https://".
Have a look at this:
Code:
sed -ni '/^http[s]*:\/\//p' infile
 
1 members found this post helpful.
Old 10-02-2013, 02:49 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or this:
Code:
sed -i '/^http[s]*:\/\//!d' infile
 
1 members found this post helpful.
Old 10-02-2013, 02:53 AM   #4
georgi
LQ Newbie
 
Registered: Apr 2012
Location: Bulgaria
Distribution: openSuSE
Posts: 15

Original Poster
Rep: Reputation: Disabled
Thank you guys very much!
Both commands work great.
 
Old 10-04-2013, 03:00 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
A bit late, but there is always "egrep -v '^http:|^https' <filename>"
 
2 members found this post helpful.
  


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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
[SOLVED] Find the lines starting with "=" and ends with "BST" vaibhavs17 Programming 9 05-19-2013 09:46 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 06:41 PM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 08:36 AM
How do I remove all lines starting with "-CONFIG_" from a file ? Glenn D. Linux - Kernel 4 10-05-2010 09:36 AM

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

All times are GMT -5. The time now is 06:38 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