Batch file 如何使用命令提示符添加一行文本并保存?
我正在寻找使用CMD在文本文件中添加一行的方法 以下是原始文件 我想补充一点 “updateLocations”:“false”在该行中 结果Batch file 如何使用命令提示符添加一行文本并保存?,batch-file,cmd,Batch File,Cmd,我正在寻找使用CMD在文本文件中添加一行的方法 以下是原始文件 我想补充一点 “updateLocations”:“false”在该行中 结果 使用python脚本完成可以从命令行调用的任务 #!/usr/bin/env python import os, sys import json if len(sys.argv) != 2: print('invalid input arguments.') print('python3 insert_update_locations
使用python脚本完成可以从命令行调用的任务
#!/usr/bin/env python
import os, sys
import json
if len(sys.argv) != 2:
print('invalid input arguments.')
print('python3 insert_update_locations_false.py [file_name]')
exit()
file_name = sys.argv[1]
def main():
print_job = read_file_in()
print_job['updateLocations'] = False
rewrite_file(print_job)
def read_file_in():
with open(file_name, 'r') as f:
jsonObj = json.load(f)
return jsonObj
def rewrite_file(jsonObj):
with open(file_name, 'w') as f:
json.dump(jsonObj, f)
main()
然后可以从命令行调用它,如下所示:
python3 insert_update_locations_false.py job1.txt
这不是
add
和update
操作吗?如果您在OSX或Linux上,您可以使用nano文本编辑器。我假设通过CMD,您指的是windows命令行。
#!/usr/bin/env python
import os, sys
import json
if len(sys.argv) != 2:
print('invalid input arguments.')
print('python3 insert_update_locations_false.py [file_name]')
exit()
file_name = sys.argv[1]
def main():
print_job = read_file_in()
print_job['updateLocations'] = False
rewrite_file(print_job)
def read_file_in():
with open(file_name, 'r') as f:
jsonObj = json.load(f)
return jsonObj
def rewrite_file(jsonObj):
with open(file_name, 'w') as f:
json.dump(jsonObj, f)
main()
python3 insert_update_locations_false.py job1.txt