Home > Blockchain >  How to add every word at the end of the every line ? word and lines are in different txt file
How to add every word at the end of the every line ? word and lines are in different txt file

Time:12-04

My file contains some urls in urls.txt Another file contains some different words in words.txt

I need to be add every word at the end of the every url.

I want output like (line by line)

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

I just want single line command :)

like

urls.txt   words.txt >> output.txt

CodePudding user response:

Given:

cat words.txt
hi
hello
there

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

You can use awk this way:

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

Prints:

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