LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-17-2009, 05:08 PM   #1
zcrxsir88
Member
 
Registered: Oct 2004
Location: Cardiff-by-the-Sea, CA
Distribution: Fedora X & RHEL X.X
Posts: 51

Rep: Reputation: 18
Help with Sed Statement


Hey all,

I'm trying to do a sed statement and having some trouble. The data I'm trying to parse looks as such: (there are multiple lines throughout the file.

Code:
192.168.1.55:," 21/tcp open ftp HP JetDirect ftpd23/tcp open telnet HP JetDirect printer telnetd (No password)80/tcp open http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)443/tcp open ssl/http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)515/tcp open printer631/tcp open http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)9100/tcp open jetdirect? ", 00:00:00:00:00 (Hewlett-Packard Company), printer
What I'm needing to do is place a carriage return at the beginning of every port.

So the output would look as such:

Code:
192.168.1.55:," 21/tcp open ftp HP JetDirect ftpd
23/tcp open telnet HP JetDirect printer telnetd (No password)
80/tcp open http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)
443/tcp open ssl/http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)
515/tcp open printer
631/tcp open http HP JetDirect Card in a LaserJet printer (HP-ChaiServer Embedded VM 3.0)
9100/tcp open jetdirect? ", 00:00:00:00:00 (Hewlett-Packard Company), printer
Since the port range will go from 1 -65535, I need it to do any that it finds.

I tried using this sed statement"

Code:
 sed 's/\"[1-9]*\\/tcp"/\\n\\r\1/g'
But it' replacing the port/tcp syntax entirely.

Can anyone help?

Thanks!
 
Old 03-17-2009, 05:19 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,613
Blog Entries: 1

Rep: Reputation: 1048Reputation: 1048Reputation: 1048Reputation: 1048Reputation: 1048Reputation: 1048Reputation: 1048Reputation: 1048
Does it do the job?
Quote:
sed 's:[0-9]*/tcp:\n&:g' file

Last edited by sycamorex; 03-17-2009 at 05:21 PM.
 
  


Reply

Tags
nmap, script, sed


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
Problem with if statement in a find -exec statement romsieze Programming 2 10-02-2008 01:38 AM
sed parsing into sql statement kcorkran Linux - Newbie 5 02-29-2008 04:04 AM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 09:05 PM
decoding a sed statement Steve Riley Linux - General 3 01-26-2005 12:50 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


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