Linux/Unix — 管道输出以加入

标签 linux unix join task

我在 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.]+)/|\1|\2/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

如果需要,我可以发布此练习的所有部分,但我想您可能知道我需要在这部分做什么。 主要是我需要知道加入意味着什么。我在 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

我不确定你是如何判断哪个是必需的,除非将“从标准输入和quotes.comms中读取”解释为标准输入优先和quotes.comms第二。

关于Linux/Unix — 管道输出以加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28092253/

相关文章:

linux - openssh - 从文件中读取

Bash:使用命令作为参数(特别是 cd、dirname 和 find)

涉及超过 2 个表的 mySQL SELECT Left Outer Join

php - 用于从单个数据库中的多个表中进行选择的 SQL 查询

C - 如何在 Linux 下重置 USB 总线?

python - 使用python找出谁在linux上登录

linux - 使用 aio_write() 但仍然看到数据通过缓存?

linux - 如何在bash中光标闪烁之前粘贴文件内容?

linux - 为用户/世界保留组的 Unix/Linux 文件权限更改

sql - 在 JOIN 之后选择 DISTINCT 值