【问题标题】:How to add every word at the end of the every line ? word and lines are in different txt file如何在每一行的末尾添加每个单词?单词和行在不同的txt文件中
【发布时间】:2022-01-09 22:02:33
【问题描述】:

我的文件在 urls.txt 中包含一些 url 另一个文件在 words.txt 中包含一些不同的单词

我需要在每个网址的末尾添加每个单词。

我想要像(逐行)这样的输出

url.1/hi
url.1/hello
url.1/there
url.2/hi
url.2/hello
url.2/there
url.3/hi
url.3/hello
url.3/there

我只想要单行命令:)

喜欢

urls.txt + words.txt >> output.txt

【问题讨论】:

  • 问题看起来很简单,但是请添加您尝试过的内容。你在编程过程中遇到了什么问题?没有cat Requirement | StackOverflow.com > workDone服务

标签: linux bash awk sed


【解决方案1】:

给定:

cat words.txt
hi
hello
there

cat urls.txt
url.1
url.2
url.3

你可以这样使用awk

awk 'FNR==NR{words[++cnt]=$1; next}
    {for (i=1; i<=cnt; i++) print $1 words[i]}
' words.txt urls.txt

打印:

url.1hi
url.1hello
url.1there
url.2hi
url.2hello
url.2there
url.3hi
url.3hello
url.3there

【讨论】:

    【解决方案2】:

    这可能对你有用(GNU sed 和并行)

    parallel echo "{1}{2}" :::: urlsFile :::: wordsFile
    

    sed 's@.*@echo "&" | sed "s#.*#&\&#" wordsFile@e' urlsFile
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 2019-08-25
      • 2021-11-08
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多