Skip to content
Advertisement

Export value of corresponding site out to a new text file

I have a text file that contains two columns of data, the first column being a site ID and the second being a value. If the value is equal to 0, I want to send the corresponding site ID out to a new file. If the value is equal to 15, I want to do nothing.

Text File:

K5B2 0
K6B0 0
K6L4 0
K7W4 0
K8B0 0
K8G2 0
K8W2 0
KABE 15
KACK 15
KACY 15
KADW 15
KAFJ 15
KAFN 15
KAGC 15
KAKQ 15
KALB 15
KANP 0
KAOO 15
KAPG 15
KAQW 15
KART 15
KASH 15
KAUG 15

Attempted Script:

badcheck1=`00z_reingest_out_tmp | awk '{print $2}'`
badsitescheck=`00z_reingest_out_tmp | awk '{print $1}'`

if [ ${badcheck1} -eq "0" ];
then
echo "${sites} is fine"
else
echo "${badsitescheck}" >> out
fi

Advertisement

Answer

You can use this simple awk script:

awk '$2 == 0 { print $1 > "file.out" }' file
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement