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-20-2008, 04:48 PM   #1
tekmann33
Member
 
Registered: Nov 2006
Posts: 188

Rep: Reputation: 30
sed command help


I have a file of URL's that I need to format for a proxy server.

A snippet of the original file looks like this:

Code:
585829	http://www.substanceabusepolicy.com
586143	http://www.pubmedcentral.nih.gov/tocrender.fcgi?action=archive&journal=232#compmed
586683	http://www.trialsjournal.com
591029	http://www.geochemicaltransactions.com
591032	http://www.biology-direct.com
592554	http://www.occup-med.com
I would like it to look like this (replace the first column with "Host" and remove only the string portion of the second column "http://www" where the file looks like this:

Code:
Host	substanceabusepolicy.com
Host	pubmedcentral.nih.gov/tocrender.fcgi?action=archive&journal=232#compmed
Host	trialsjournal.com
Host	geochemicaltransactions.com
Host	biology-direct.com
Host	occup-med.com
I have been reading the sed manual but I am not sure how to limit sed to a column or only remove a portion of a string.

Last edited by tekmann33; 10-20-2008 at 04:50 PM.
 
Old 10-20-2008, 05:06 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can simply substitute the first part of every line:
Code:
sed 's/.*http:\/\/www./Host    /g' file
the same using awk:
Code:
awk '{print "Host    " gensub("http://www.","",1,$2)}' file
the same using the shell
Code:
#!/bin/bash
while read number url
do
  echo "Host    ${url#http://www.}"
done < file
 
  


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
how to use sed command raghuvamsi Linux - General 2 06-26-2008 02:17 AM
SED Command racingdynamics Linux - General 4 07-25-2006 03:09 PM
sed command rharris72 Programming 6 11-20-2005 09:26 PM
sed command pazvant Linux - Software 2 05-09-2004 01:58 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 12:27 PM


All times are GMT -5. The time now is 10:08 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration