Im trying to curl a csv file and parse it based on their property and print it back by using variable names.
File 1:
10.0.0.1,gateway,name_of_device
10.2.4.5,server,name_of_device
10.3.5.6,PC,name_of_device
My script below,
#!/bin/sh
input=$(curl http://example.com/1.txt)
ip=$(echo "$input" | awk -F ',' '{print $1}')
type=$(echo "$input" | awk -F ',' '{print $2}')
name=$(echo "$input" | awk -F ',' '{print $3}')
echo "$ip $type $name"
This prints,
10.0.0.1
10.2.4.5
10.3.5.6
gateway
server
PC
name_of_device
name_of_device
name_of_device
but the expected output should be like,
10.0.0.1 gateway name_of_device
10.2.4.5 server name_of_device
10.3.5.6 PC name_of_device
Tried different options like,
assigning output to another variable and echo'ing it,
# output="$source_ip $tag_text"
# echo -e $output
printf statements:
# printf "%-20s | %-20s" "$source_ip" "$tag_text"
# printf "$source_ip" "$tag_text"