Linux / Unix — 管道输出以加入

Linux / Unix — pipe the output to join

我在 Linux / Unix 方面还是个新手,我时常做一些练习。 我一直在做练习,直到我完成了一部分。

Plain sort quotes.t5 and pipe the output to join. In join use field separator, read from stdin and from quotes.comms, output to quotes.t6

问题是,我不明白这部分在问什么。

A few days ago I have ran this command on the server:

wget 'http://finance.yahoo.com/d/quotes.csv?s=BARC.L+0992.HK+RHT+AAPL+ADI+AEIS+AGNC+AMAT+AMGN+AMRN+ARCC+ARIA+ARNA+ATVI+BBRY+BIDU+BRCD+BRCM+BSFT+CENX+CERE+CMCSA+COCO+CSCO+CSIQ+CSOD+CTRP+CTSH+CYTX+DRYS+DTV+DXM+EA+EBAY+EGLE+ENDP+ESRX+EXPD+EXTR+FANG+FAST+FB+FCEL+FITB+FLEX+FOXA+FSLR+FTR+GALE+GERN+GILD+GMCR+GRPN+GTAT+HBAN+HDS+HIMX+HSOL+IMGN+INTC+JASO+JBLU+JDSU+KERX+LINE+LINTA+MDLZ+MNKD+MPEL+MSFT+MU+MXIM+MYL+NFLX+NIHD+NUAN+NVDA+ONNN+ORIG+OTEX+OXBT+PENN+PMCS+PSEC+QCOM+RBCN+REGN+RFMD+RSOL+SCTY+SINA+SIRI+SNDK+SPWR+SYMC+TSLA+TUES+TWGP+TXN+VOLC+WEN+YHOO+ZNGA&f=nab' -O quotes.csv

But the produced file quotes.csv was not good enough to get insight into finances and stuff so I need some help from you!

Checkpointing. When finished this lesson you must get this:

$ sha256sum -c quotesshasums
quotes.t1: OK
quotes.t2: OK
quotes.t3: OK
quotes.t4: OK
quotes.t5: OK
quotes.t6: OK
  • quotes.csv We have a source file with stock prices data Lines are terminated with CRLF, which is not Unix style. Make it LF terminated. Means remove CR (\r) byte from each line. To do this use sed (man sed) substitute command, output to quotes.t1 More info at http://en.wikipedia.org/wiki/Newline

  • Run checkpoint to test if quotes.t1 is OK.

  • Use head and tail commands to output all except first and last line of file quotes.t1 to quotes.t2

  • Make fields separated with pipe (vertical bar |) instead of comma.

    sed -re 's/,([0-9.]+),([0-9.]+)/||/g' quotes.t2 > quotes.t3
    
  • Numeric sort by third field(key), don't forget the new separator, output to quotes.t4q Output last five lines, cut it leaving first and third fields in result. quotes.t5

  • Plain sort quotes.t5 and pipe the output to join. In join use field separator, read from stdin and from quotes.comms, output to quotes.t6

如果需要,我可以 post 这个练习的所有部分,但我想你可能知道我在这部分需要做什么。 主要是我需要知道加入意味着什么。我在 Google 上搜索过这个,但我还是不明白。

正在将评论的缩写版本转换为答案。

问题的原始版本是关于:

Plain sort quotes.t5 and pipe the output to join. In join use field separator, read from stdin and from quotes.comms, output to quotes.t6

你要知道join是一个命令。如果您指定 - 作为它的两个输入文件名之一,它可以从标准输入读取。

然后,在我看来,步骤非常简单:

sort quotes.t5 | join -t'|' - quotes.comm > quotes.t6

或者也许:

sort quotes.t5 | join -t'|' quotes.comm - >quotes.t6

我不确定你是怎么说出哪个是必需的,除非首先将 'read from stdin and quotes.comms' 解释为标准输入,然后再将 quotes.comms 解释为标准输入。