-2

I'm trying to create a second config file from a file with a list of domains.

File1 (file1.txt) contents

example.com  
example.org  
example.net  
.
.
.

I want to automatically create this second file (file2.txt) with the contents like this.

blahblahblah /something/example.com  /something/exmaple.org  /something/example.net......

Seems simple enough but I can't figure it out. I'm able to make a list of domains (file1.txt) and I just need to create this second file which I'll be using as part of a config file.

2
  • It's not quite clear what the real problem is. The example looks incorrect.
    – U. Windl
    Oct 8, 2021 at 7:53
  • If we know what format the configuration file uses, we could solve this properly by outputting it in the correct form.
    – Kusalananda
    Oct 8, 2021 at 8:12

2 Answers 2

1

awk approach:

awk 'BEGIN{ printf "blahblahblah" }{ printf " /something/%s", $0 }
     END{ print "" }' file1.txt > file2.txt
0

With sed

sed -n '
    s,^,/something/,
    1s/^/blahblahblah /
    H
    ${g;s/\n/ /gp}
' file1.txt > file2.txt

with bash

(   printf "blahblahblah" 
    mapfile -t lines < file1.txt
    printf " /something/%s" "${lines[@]}"
    echo 
) > file2.txt

or

{   printf "blahblahblah" 
    while IFS= read -r line; do printf " /something/%s" "$line"; done < file1.txt
    echo 
} > file2.txt
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .