I have not used bash often in the past for bash scripting & I am currently reading using bash scripting. The file contains a number of fields stored in csv format. The first scipt below will gather all the ips in a file; however, I am also trying to gather the IP and another field called Network.. Does anyone know I can achieve this?
files=`ls | grep data_batch_`
for file in ${files[@]}
do
cat ${file} | cut -d , -f2 | grep -v "IP" > data_${file}
done
I have tried do add a boolean operator but I have no success. Also tried more pipes. I have not used bash often so I may be missing something with the syntax or not understanding why this is not a allowed?
files=`ls | grep data_batch`
for file in ${files[@]}
do
cat ${file} | cut -d , -f2 | cut -d, -f3 | grep -v "IP" && "Network" > data_${file}
done
For some reason when I do this, it appears to overwrite the IP value with the NETWORK value, instead of storing them both. Essentially, all I am trying to do is print two fields to a file instead of one, but I am not sure how to achieve his solution. Any tips will also help.
My desired output is the ip address value and the network value stored in the file. At the moment, all I get is the IP. The desired output below.
1.1.1.1
Network5