I have a text file similar to below
https://hosted.example.com [403]
https://checkout.example.com [200]
https://lib.example.com [403]
http://autodiscover.example.com [301]
https://go.example.com [503]
https://qa.example.com [403]
https://qalib.example.com [403]
https://join.example.com [200]
The file has similar lines with status codes in the second column like the above sample data. I want to create files based on the second column, if the second column has a value of 200 then that line has to be redirected to 200.txt and this follows with every status code.
Script used:
list=('[403] [401] [404] [503] [301] [302] [200]')
for i in $list
do
filename=$(echo $i | cut -d "[" -f2 | cut -d "]" -f1)
awk '$2 == "$i"' file.txt | awk '{print $1}' > $filename.txt
done
The problem with the script is it create files but the value of column 1 is not redirected to the respective files.