Parsing a tab seperated zone file in shell
For a research project, I wanted to analyze domain names.
I got a copy of a zone file that was tab seperated.
Before I could load it into pandas
or r
, I wanted to data munge it a bit.
Doing in shell was pretty straightforward and neat!
bash
FILE=~/Downloads/academy.txt
# show first 10 lines
cat $FILE | head -n 20
# script to parse zone file
# credit: https://stackoverflow.com/questions/9736202/read-tab-separated-file-line-into-array
while IFS=$'\t' read -r -a myArray
do
echo "${myArray[0]} ${myArray[1]} ${myArray[2]} ${myArray[3]}"
done < $FILE