追加内容到一个文件,如果不存在使用逗号值
我们有一个名为parameters.txt文件,其中包含逗号分隔值:
We have a file named parameters.txt which contains in comma separated value:
db.hostname,db.username,db.password,db.url,db.status,codesettingsA, codesettimgsB
另外,我们有一个主文件名为的properties.txt其中包含行格式
Also, we have a main file called properties.txt which contains in Line format
db.hostname=hostname
db.username=username
db.password=password
我需要通过逗号分隔值parameters.txt并检查是否如果是的properties.txt存在。如果不存在,它应该打印的properties.txt底部
I need to pass the comma separated values in parameters.txt and check whether if it is exist in properties.txt. If it is not exist it should print bottom of the properties.txt
例如,在的properties.txt:db.url配置参数,db.status,codesettingsA和codesettimgsB是不存在的。不过,我从parameters.txt传递。它应该被追加和结果应该是像这样的properties.txt:
For Example, in the properties.txt: db.url, db.status, codesettingsA and codesettimgsB is not there. However, I’m passing from the parameters.txt. It should be appended and the result should be like this in properties.txt:
db.url
db.status
codesettingsA
codesettimgsB
请注意:已值申报db.hostname =主机名,db.username =在属性文件中的用户名和db.password =密码。我路过分贝,主机名,db.username,db.password从参数文件。所以,这甚至应该逗号后忽略值,不应打印分贝,主机名,db.username,db.password
Note: Already values are declared for db.hostname=hostname, db.username=username and db.password=password in properties file. I'm passing db,hostname,db.username,db.password from parameter file. So, this should ignore the values even after the comma and shouldn't print db,hostname,db.username,db.password
时那里的properties.txt底部页打印他们的任何方式?
你能否提供样品code?
Is there any ways to print them at the bottom page of properties.txt? Can you provide sample code?
您可以使用此AWK:
awk 'FNR==NR{for (i=1; i<=NF; i++) a[$i]; next} $1 in a{delete a[$1]} 1;
END{for (i in a) print i "="}' FS=' *, *' params.txt FS=' *= *' props.txt
输出:
db.hostname=hostname
db.username=username
db.password=password
codesettimgsB=
db.url=
codesettingsA=
db.status=