LinuxQuestions.org
Help answer threads with 0 replies.
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 02-02-2018, 10:39 AM   #1
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Rep: Reputation: Disabled
how to delete exact "http://" in text with sed


imagining that you have a file with these urls :

http://someurl.com/......
http://
http://anotherurl.com

How to delete that 2nd line only with sed , by making sed search for it and delete it .
 
Old 02-02-2018, 11:03 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Don't need to use sed for it.

Code:
grep -v ^http://$ test.txt > clean.txt
 
1 members found this post helpful.
Old 02-02-2018, 11:13 AM   #3
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
not working .

using :
Quote:
sed 's/http\?:\/\///'
will delete all http:// in file , and i just want those alones .

Last edited by pedropt; 02-02-2018 at 11:16 AM.
 
Old 02-02-2018, 11:15 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Works fine for me:
Code:
[grantm@web103 ~]$ cat test.txt
http://someurl.com/......
http://
http://anotherurl.com
[grantm@web103 ~]$ grep -v ^http://$ test.txt > clean.txt
[grantm@web103 ~]$ cat clean.txt
http://someurl.com/......
http://anotherurl.com
[grantm@web103 ~]$
 
2 members found this post helpful.
Old 02-02-2018, 11:30 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@pedropt:Indeed, that doesn't work. How about adding ^ and $ ?
Code:
sed 's;^http://$;;'
 
Old 02-02-2018, 11:33 AM   #6
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
Quote:
sed 's;^http://$;;'
is not working because i am using 8 sed commands in a line variable to clear a very complicated xml file with a lot of stuff to remove .

---------------------------------------

Interesting that if i use that code on a multiple commands line it not works

like : sed something <filename | sed otherstuff | sed morestuff | grep -v ^http://$ >newfilename

or even :

var1=$(sed something <filename | sed otherstuff | sed morestuff | grep -v ^http://$ )
echo $var1 > filename2

but if i use it alone it works .

Why is this happening ? Does anyone knows ?

Last edited by pedropt; 02-02-2018 at 11:36 AM.
 
Old 02-02-2018, 11:45 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Kindly read this: https://stackoverflow.com/help/mcve
 
Old 02-02-2018, 11:59 AM   #8
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 345

Original Poster
Rep: Reputation: Disabled
eventually i fixed the issue , but i got a new issue , now with tr command to split the lines i text , but i will create a new thread .

The way i solve this issue was from first line of commands create an output , and then after that i used that output with the grep command you provided to create a new clean file without the http:// .

thanks .
 
  


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] Delete lines from a text file not starting with "http://" or "https://" georgi Programming 4 10-04-2013 03:00 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 06:41 PM
bad: Want to insert a line into a text file using "sed" command eliote Linux - General 7 09-19-2010 02:55 AM
sed error "command c expects \ followed by text" under OS X (but works in Linux) srunni Programming 3 12-02-2009 02:52 AM
"socks5" -> "http" proxy protocol, or ssh tunnel to sock5 ? I'm beyond http p vmicho Linux - Networking 2 12-16-2003 05:32 AM

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

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