将文本文件集的内容复制到其他文本文件集中

时间:2019-03-07 21:07:44

标签: bash unix

我位于一个包含一组文件夹A1-7和B1-7的目录中,因此如果我输入“ ls”命令,将会看到以下内容。

A1 A2 A3 A4 A5 A6 A7 B1 B2 B3 B4 B5 B6 B7 

B文件夹包含一个文本文件,而A文件夹包含输入文件和提交脚本。这些文件以其包含的文件夹命名,例如,A1文件夹包含A1.inp和A1.sub,而B1文件夹包含B1.txt。

目标是将B1文本文件的内容复制到A1输入文件中的特定位置,特别是在文本字符串“ xyz”下方。同样,应将B2文本文件复制到“ xyz”字符串的A2输入文件中。

是否有一个命令/脚本可以将B文本文件的所有内容添加到相应的A输入文件中?

1 个答案:

答案 0 :(得分:1)

类似的事情应该起作用:

p = float(input('Please enter principal amount:'))
t = float(input('Please enter number of years:'))
r = float(input('Please enter rate of interest:'))
n = float(input('Please enter number of times the interest is compounded in a year:'))
a = p*(1+(r/(100*n))**(n*t))
print('Amount compounded to: ', a)

sedfor i in {1..7}; do sed -i '/xyz/r B${i}/B${i}.txt' A${i}/A${i}.inp; done 标志意味着就地编辑文件(A#.inp)。单引号中的部分是您要在该文件上执行的命令; -i附加从文件名(B#.txt)中读取的文本。