![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Content extract of a file using awk | nr_shan | Shell Programming and Scripting | 5 | 12-19-2007 05:22 AM |
| How to insert text into first line of the file and middle of the file? | ali hussain | Shell Programming and Scripting | 3 | 03-05-2007 05:54 AM |
| Insert file content to a file | Manan | UNIX for Advanced & Expert Users | 2 | 12-09-2005 09:17 AM |
| transfer of specific file content to another file | mem101 | Shell Programming and Scripting | 1 | 10-18-2005 02:01 PM |
| Insert file content via sed after two searchings | nir_s | Shell Programming and Scripting | 2 | 09-13-2005 06:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
extract content from a file and insert to another file
please help for the following task...
I have to extract the mac address & IP address from the file1: ... 0100004512EEF4 03 192.168.0.7 192.168.0.1 -1 ... 0100779hF5D212 03 192.168.0.8 192.168.0.1 -1 ... 0100789lF5D212 03 192.168.0.9 192.168.0.1 -1 ... ... change the format (addidng colon) and insert into file 2 ... host { hardware ethernet 00:00:45:12:EE:F4; fixed-address 192.168.0.7; } host { hardware ethernet 00:77:9h:F5 2:12;fixed-address 192.168.0.8; } ... please tell me how I can exact the data and change the format and insert into another file, thanks! |
|
||||
|
Quote:
there seems to be a little problem, as I ONLY want to extract the first and 3rd field for each line. |
|
||||
|
Python alternative
Code:
#!/usr/bin/python
o = open("file2.txt","a")
for line in open("input.txt"):
splitted = line.split()
mac, ip = splitted[0] , splitted[2]
out = """
host {
hardware ethernet %s;
fixed-address %s;
}
""" %(mac,ip)
o.write(out + "\n")
o.close()
|
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|