sed - delete everything from the first IP in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - delete everything from the first IP in the file
# 1  
Old 04-08-2013
sed - delete everything from the first IP in the file

Hi,

I have a text file with content as follows:
Code:
servers list ips 10.10.10.1 test 2 3 4
desktop station 10.10.10.3 4 test 4
laptops quesy 2013 2012 10.100.18.0 test 4 6 8

all I need is:
Code:
servers list ips
desktop station
laptops quesy 2013 2012

All I need is the correct command or script that would delete everything on each line from the IP address on each line in the file. Each line has IP address in it.
# 2  
Old 04-08-2013
Code:
sed 's/[0-9]*\..*//g' file

# 3  
Old 04-08-2013
Did not work since some of the line has the following:
Code:
servers list ips 10.10.10.1 test 2 3 4
desktop station 10.10.10.3 4 test 4
laptops quesy 2013 2012.142537 10.100.18.0 test 4 6 8

What do I need to add to the following line to have it delete everything from the IP address

sed 's/[0-9]*\.[0-9]*\.*\.[0-9]*\.*\.[0-9]*\.*//g' file

output
Code:
servers list ips  test 2 3 4
desktop station  4 test 4
laptops quesy 2013 2012.142537  test 4 6 8

regards,
# 4  
Old 04-08-2013
Code:
$ sed -r 's/ [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ .*//g' file     
servers list ips
desktop station
laptops quesy 2013 2012.142537

OR
Code:
$ sed 's/ [0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+ .*//g' file
servers list ips
desktop station
laptops quesy 2013 2012.142537

# 5  
Old 04-09-2013
Thank you all. it works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete line from file using sed command?

hello Team, I want to delete below linux using sed command but I am getting error.sed -i '/url=/status.cgi?hostgroup=/d' 3 error:sed: -e expression #1, char 32: unknown option to `s' Could you please help me with correct syntax. My line contain / character because of that I am getting... (4 Replies)
Discussion started by: ghpradeep
4 Replies

2. Shell Programming and Scripting

sed to delete items in an array from a file

I need to create a shell script to delete multiple items (Strings) at a time from a file. I need to iterate through a list of strings. My plan is to create an array and then iterate through the array. My code is not working #!/bin/bash -x declare -a array=(one, two, three, four)... (5 Replies)
Discussion started by: bash_in_my_head
5 Replies

3. Shell Programming and Scripting

sed to delete selected line from file

Ultimate goal is to delete lines from before and after a block of lines in a given file. First attempt was something like this: sed -e '1,/STARTUP/ d' inputfile.txt > outputfile.txt but that deleted everything down to and including the line with STARTUP. I need to delete everything before... (6 Replies)
Discussion started by: edstevens
6 Replies

4. Shell Programming and Scripting

Using Sed to Delete Words in a File

This is a Nagios situation. So i have a list of servers in one file called Servers.txt And in another file called hostgroups.cfg, i want to remove each and every one of the servers in the Servers.txt file. The problem is, the script I wrote is having a problem removing the exact servers in... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. UNIX for Dummies Questions & Answers

sed how to delete between two words within a file

I'm hoping someone could help me out please :) I have several .txt files with several hundred lines in each that look like this: 10241;</td><td>10241</td><td class="b">x2801;</td><td>2801</td><td>TEXT-1</td></tr> 10242;</td><td>10242</td><td... (4 Replies)
Discussion started by: martinsmith
4 Replies

6. Shell Programming and Scripting

how to delete \n in a large file with sed

Hello i have a big file with a specific format and delimiter is "§" : §field1§$field2§$field3§$field4§$field5§$field6§$field§ in this file we have a field which are very long (more than 20000 chars !!!!) so through vi i cant manipulate them. despite this i managed to suppress lines that... (11 Replies)
Discussion started by: ade05fr
11 Replies

7. Shell Programming and Scripting

Using SED to delete some lines from file

Hi All, I have one /etc/hosts.equiv file which has following entries ########## wcars42g admin wcars42b netmgr wcars42b oemssrvr wcars42f admin wcars42f netmgr wcars42f oemssrvr ########## I am trying to delete lines starting from wcars42b.... (1 Reply)
Discussion started by: akash_mahakode
1 Replies

8. Shell Programming and Scripting

delete multiline string from file using sed.

Hi, I have file which has the following content... GOOD MORNING **********WARNING********** when it kicks from the kickstart, sshd daemon should start at last. (WHEN KICKING ITSELF, NOT AFTER KICKING). /etc/rc3.d/S55sshd ( run level specification for sshd is 55, now I would want to... (4 Replies)
Discussion started by: skmdu
4 Replies

9. Shell Programming and Scripting

Delete particular value from file using 'sed'

Hi, I have two files test1,test2. If the number in test1 file exist in test2 then i want to remove that from test2 file. Ex: File- test1 12 13 14 15 ============== File- test2 1A~12 2B~13 3C~33 4D~22 I want to remove row which contains 12,13 from test2. I am using this sed... (2 Replies)
Discussion started by: sai_nj
2 Replies

10. Shell Programming and Scripting

delete line in file with sed

sed "/$titlesearch/d" movielist will delete any line in the file movielist that matches $titlesearch, but this is only a screen print correct ? how can I have sed to actually delete the line from the file so that it doesnt appear next time I open the file ? thanks Steffen (8 Replies)
Discussion started by: forever_49ers
8 Replies
Login or Register to Ask a Question