my aim is to convert these ip address to a decimal form using this formula
so if my ip address is 192.168.1.2
my result
so for input file, my output file has to be
First, sed does not have the ability to perform arithmetic operations on strings. Second, your first sed command does not contain a valid substitute command. Third, your second sed command tries to edit a directory (i.e., ./) and sed only operates on text files; not directories. And, fourth, the regular expression that is your search pattern in your second sed command looks for a single digit followed by a plus-sign followed by a period followed by a single digit followed by a plus-sign followed by a period followed by a single digit followed by a plus-sign followed by a period followed by a single digit, but that pattern does not match any text in any line in your sample input.
The awk utility, however, is perfectly capable of simple arithmetic like this. However, you will not get unique integer values if any of the four numbers in an IP address is larger than 255 with the algorithm you're using to convert an IP address to an integer AND, I don't get the output values you say you expect for any of the in IP addresses you supplied??? If all four numbers in your IP addresses are in the range 0 through 255, using the algorithm you specified, the result will fit in an unsigned 32-bit integer. It will fit in a signed 32-bit integer if and only if the 1st number is in the range 0 through 127.
You might try the following awk script and see if it comes close to the results you want:
with the sample input you showed us in post #1, the above code produces the output:
Note that there is an empty field before the two added fields in all but the last line of input because your sample input file has an empty field (i.e., a tab character) at the end of each of those lines.
You didn't tell us what shell or operating system you're using. If you want to try this on a Solaris/SunOS system, change awk in the above script to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
Hi,
I want to replace the value in more than one column.
For one column ,following command is working -
sed 's/./$value_to_replace/$column number' file_name
e.g. suppose this is input 1111000000
command - sed 's/./M/5'
output= 1111M000000
For two column also command is like -
cat... (22 Replies)
I have the input file like this.
Input file: 12.txt
1) There are one or more than one <tr> tags in same line.
2) Some tr tags may have one <td> or more tna one <td> tags within it.
3) Few <td> tags having "<td> </td>". Few having more than one " " entry in it.
<tr> some td... (4 Replies)
how to search and replace string in column in file with command sed or other
search "INC0000003.in" and replace column 4 = "W"
$ cat file.txt
INC0000001.in|20150120|Y|N|N
INC0000002.in|20150120|Y|N|N
INC0000003.in|20150120|Y|N|N
INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Hi All,
I have a file example.csv which looks like this
GrpID,TargetID,Signal,Avg_Num
CSCH74_1_1,2007,61,256
CSCH74_1_1,212007,647,679
CSCH74_1_1,12007,3,32
CSCH74_1_1,207,299,777
I want the output as
GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num
CSCH74_1_1,2007,61,256... (1 Reply)
Hi All,
I have a file example.csv which looks like this
GrpID,TargetID,Signal,Avg_Num
CSCH74_1_1,2007,61,256
CSCH74_1_1,212007,647,679
CSCH74_1_1,12007,3,32
CSCH74_1_1,207,299,777
I want the output as
GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num
CSCH74_1_1,2007,61,256... (4 Replies)
Hello,
I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2
SDF4 -0.211654
SDF4 0.978068
... (1 Reply)
I have a base file FILE1 with the following data
FILE1.dat
21111111110001343 000001004OLFXXX029100020091112
21111111110000060 000001004ODL-CH001000020091112
22222222220000780 000001013OLFXXX006500020091112
23333333330001695 000001039OLFXXX030600020091112
23333333330000111... (2 Replies)
the following command removes the first two characters of the first column, how can I change it to to remove the first two characters of the second column?
sed 's/^..//' file1.txt > file2.txt
Thanks
Joseph (4 Replies)