我正在尝试从包含域列表的文件创建第二个配置文件。
文件1(文件1.txt)内容
example.com
example.org
example.net
.
.
.
我想自动创建第二个文件(file2.txt),其内容如下。
blahblahblah /something/example.com /something/exmaple.org /something/example.net......
看起来很简单,但我无法弄清楚。我可以创建一个域列表(file1.txt),我只需要创建第二个文件,我将使用它作为配置文件的一部分。
答案1
awk
方法:
awk 'BEGIN{ printf "blahblahblah" }{ printf " /something/%s", $0 }
END{ print "" }' file1.txt > file2.txt
答案2
与 sed
sed -n '
s,^,/something/,
1s/^/blahblahblah /
H
${g;s/\n/ /gp}
' file1.txt > file2.txt
用bash
( printf "blahblahblah"
mapfile -t lines < file1.txt
printf " /something/%s" "${lines[@]}"
echo
) > file2.txt
或者
{ printf "blahblahblah"
while IFS= read -r line; do printf " /something/%s" "$line"; done < file1.txt
echo
} > file2.txt