Organizational Research By

Surprising Reserch Topic

boostr.in questions - Question:Sed - modify single character in first column without touching others


I've got a list of interfaces that I need to modify the original files . to : so I can feed them into an ifconfig script.

It looks basically like this:

eth0.1 192.168.0.1 255.255.255.0

eth0.2 192.168.1.1 255.255.255.0

eth0.3 192.168.2.1 255.255.255.0

Using my basic sed knowledge I can do the following:

sed -i 's/\./\:/g'

which turns all . into :.

eth0:1 192:168:0:1 255:255:255:0

Now, if I weren't modifying the original file I know I could awk '{print $1}' however I don't know how to do this when using sed -i.

I should mention that there are also certain lines that are not subinterfaces such as:

eth1 10.10.10.1 255.255.255.0

Dropping the g in sed (which I'm sure it's the right direction) unfortunately modifies the first octet for these lines to:

eth1 10:10.10.1...
asked Sep 13, 2013 in LINUX by anonymous
edited Sep 12, 2013
0 votes
19 views



Related Hot Questions



Government Jobs Opening


...