hello all,
I have files that have a specific way for naming the first column
they are make of five names in Pattern of 3
Y = [james mark john peter sam] (no case sensitive)
so the files are names $Y-$Y-$Y or $X-$Y-$Z depending how we look
they only exist of the pattern exist
now I want to create a file from them that if a specific patter for that column didnt exist it will write the pattern and write "NA" for the rest of the columns
so basically I should have 125 lines and if the match exist it will write itself
else print NA
for X in james mark john peter sam
do
name=$(basename $X)
if [ -s $X ]
then
grep count/$X-$X-$X file01 | awk �{print $0}� >> file02.txt
else
echo "count/$X-$X-$X NA NA NA NA" >> file02.txt
fi
done
I am doing this but its not working not sure what I am doing wrong :wall::wall::wall:
can you please help
I have this now which print the 125 right but all with NA and dont get the pattern right
for X in james mark john peter sam
do
for Y in james mark john peter sam
do
for Z in james mark john peter sam
do
name=$(basename $X)
if [ -s $X ]
then
grep -o count/$X-$Y-$Z file01 | awk �{print $0}� >> file02.txt
else
echo "count/$X-$Y-$Z NA NA NA NA" >> file02.txt
fi
done
done
done
for X in james mark john peter sam
do
for Y in james mark john peter sam
do
for Z in james mark john peter sam
do
if [[ `grep "$X-$Y-$Z" -c file01` -gt 0 ]]
then
grep -o "$X-$Y-$Z" file01 >> file02.txt
else
echo "$X-$Y-$Z NA NA NA NA" >> file02.txt
fi
done
done
done
yap, if the line exist it only prints
count/$X-$Y-$Z and not the rest of the row
I can see now that GREP -O is not correct for start
solved I guess ... it should be -w instead of -o to get the whole line
but dont know y I dont get 125 for all the files in one directory
FILES01="F1/*"
for T in $FILES01
do
name=$(basename $T)
for X in james mark john peter sam
do
for Y in james mark john peter sam
do
for Z in james mark john peter sam
do
if [[ `grep "$X-$Y-$Z" -c $T` -gt 0 ]]
then
grep -w "count/$X-$Y-$Z" $T >> normal/$name
else
echo "count/$X-$Y-$Z" >> normal/$name
fi
done
done
done
done
there is no NA in any of the files
even without -w or -o i still dont get 125 ... i get different rows for different files
I think i found the problem