Created
December 21, 2020 20:44
-
-
Save cameronbourke/a89eb1550c75a4f50e95103f11aea312 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
decimal=243881281 | |
function dec2ip { | |
local v=$1 | |
local i1=$((v>>24 & 255)) | |
local i2=$((v>>16 & 255)) | |
local i3=$((v>>8 & 255)) | |
local i4=$((v & 255)) | |
printf '%d.%d.%d.%d\n' $i1 $i2 $i3 $i4 | |
} | |
data=$'243881281,243881281\n243881282,243881282\n243881283,243881283' | |
echo "\$IFS: $IFS" | |
printf $"ip1, ip2\n$( | |
echo "$data" | while IFS=, read -r ip1 ip2; do | |
echo "$(dec2ip $ip1), $(dec2ip $ip2)" | |
done)" > output.csv | |
#while IFS=\n, read -r field1 field2 | |
#do | |
# echo "field1: $field1, field2: $field2" | |
# #echo "$(dec2ip field1), $(dec2ip field2)" | |
#done <<< $data | |
dec2ip $decimal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment