I came across some problem with playing with grep ; and probably about grepping a tab. I have two files shown as below, both of which are tab-delimited.
FM_DEL_50r.bed
chr1 3392391 3658426 DEL chr1 3392364 3658425 DEL
chr1 4011952 4392064 DEL chr1 4011953 4392062 DEL
chr1 4468526 4665322 DEL chr1 4468523 4665322 DEL
FC_DEL_50r.bed
chr1 2612264 2613324 DEL chr1 2612205 2613007 DEL
chr1 3392391 3658426 DEL chr1 3392391 3658426 DEL
chr1 4011952 4392064 DEL chr1 4011953 4392060 DEL
我希望两处档案中都有一些内容:
cat FC_DEL_50r.bed |grep `cat FM_DEL_50r.bed |head -2|tail -1|awk {print $2" "$3} `
但有错误:
grep: 4392064: No such file or directory
I Trial cat _DEL_DEL_bed head hexachloro FM-1FMkprint{ 2, “$3}
, 实际操作和产出401 1952 4392064
So maybe we cannot grep format like number" "number"? thx
edit: how stupid I am. I should use double-quotes..........(I first used single-quote and didn t work...)
cat FC_DEL_50r.bed |grep "`cat FM_DEL_50r.bed |head -2|tail -1|awk {print $2" "$3} `"
Follow-up questions: I wrote a bash script, based on the questions above:
#!/bin/bash
for((c=1;c<=542;c++))
do
LINE=`head -$c FM_DEL_50r.bed|tail -1`
P1=`cat $LINE|awk {print $1"\t"$2"\t"$3} `
GREP1=`cat FC_DEL_50r.bed |grep "$P1"`
X1=`cat $GREP1 |awk {print $5"\t"$6"\t"$7} `
P2=`cat $LINE|awk {print $5"\t"$6"\t"$7} `
GREP2=`cat MC_DEL_50r.bed |grep "$P2"`
X2=`cat $GREP2 |awk {print $5"\t"$6"\t"$7} `
if [ $X1 -eq $X2 ]
then
echo "$LINE" "$X1"
fi
done
然而,它生产的产品
cat: chr1: No such file or directory
cat: 27122653: No such file or directory
cat: 27446984: No such file or directory
cat: DEL: No such file or directory
cat: chr1: No such file or directory
cat: 27880115: No such file or directory
cat: 28225069: No such file or directory
cat: DEL: No such file or directory
Seems it splits all columns of one line and cannot recognize them. What s the problem this time? thx