English 中文(简体)
我怎么能够打上涉及制片的线?
原标题:How can I grep lines involving tabs?
  • 时间:2011-10-26 19:20:03
  •  标签:
  • tabs
  • grep

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

最佳回答

gr 1-o-1

<代码>grep [options] PATTERN [FILE...]

这是指在[FLE......]档案中显示的颗粒状。

型轴线不能有空间或表象(无所引述),因为然后将评估作为围护理由。 因此,在你的情况下,指挥实际上变成了。

<代码> CA_DEL_50r.bed repg 401 1952 4392064

第二部分(After 管道)基本上要求将439206(Which需要作为档案)的401 1952(主人) gr成)。

为了纠正这种情况,在您的第二次发言中增加两点:

cat FC_DEL_50r.bed |grep "cat FM_DEL_50r.bed |head -2|tail -1|awk {print $2" "$3} "

+1 所涉所有细节。

问题回答

出现错误是因为背书。 <代码>wk输出到<代码>grep 理由清单。 因此,你正在做以下工作:

cat FC_DEL_50r.bed |grep 4011952 4392064

<代码>grep, 当然,401 1952<>/code>为: regex and 4392064, 即为档案名称,不能找到后者。

With the double quotes that you have now added around the argument list, you are getting:

cat FC_DEL_50r.bed |grep "4011952 4392064"

如果你想要的是:

cat FC_DEL_50r.bed |grep "4011952	4392064"

困难在于<代码>正在由<代码>wk解释为绕航顺序。 若要从<代码>wk上删除一个字面<代码>。

{print $2"\t"$3}




相关问题
Really strange grep 2.5.1 bug in cat d reading long lines

Recently a peer and I discovered an interesting bug in GNU grep 2.5.1 in which standard input with lines greater than 200,000,000 characters causes grep to fail, even if the pattern is not in one of ...

grep a tab in UNIX

How do I grep tab ( ) in files on the Unix platform?

how to grep a variable in the shell program? [duplicate]

#!/bin/bash for ((var=0; var<20; var++)) do echo " Number is: $(grep Multiple_Frame = echo **$var** 20mrf.txt | wc -l)" >>statisic.txt done This shell program cannot produce correct ...

GREP - finding all occurrences of a string

I am tasked with white labeling an application so that it contains no references to our company, website, etc. The problem I am running into is that I have many different patterns to look for and ...

Grep doesn t work correctly with .as files

Here s the statement I m running: grep -i -H ConfigureControls *.as Note that I m forcing file names with the -H flag. What I get back is: } } trac} } this.chairControls.debug....

热门标签