I have a comma delimited text file on a Linux machine. First I want to match col1 with col4 and col5, if col1 matches with col4 then print all values from col4 in all rows where col1 is empty and if if col1 matches with col5 print all values from column 5 in all rows where col1 is empty until a new value appears in column1. Input file:
va,group,subgroup,minor,major
A,AGT,rs123,A,G
,AGT,rs456,G,T
,AGT,rs457,T,G
,AGT,rs667,A,T
G,GSTT1,rs234,A,G
,GSTT1,rs668,T,G
,GSTT1,rs556,A,G
Expected output:
va,group,subgroup,minor,major
A,AGT,rs123,A,G
G,AGT,rs456,G,T
T,AGT,rs457,T,G
A,AGT,rs667,A,T
G,GSTT1,rs234,A,G
G,GSTT1,rs668,T,G
G,GSTT1,rs556,A,G
This is what I tried:
if [ $1 == $4] && [ -z "$1" ]
then
awk -F"\t -v OFS="\t" '{ for(N=1; N<=NF; N++) if($N=="") $N=$4 } 1' file > tmp1
else
echo "stop"
fi
$1
is empty in the first line?