- 論壇徽章:
- 0
|
以上兩位給的awk和sed方案都不錯(cuò),但我的理解能力有限,擔(dān)心以后維護(hù)困難。
我還是想使用xargs來實(shí)現(xiàn),但下面的命令出錯(cuò)了:- echo '{"first_key": "value", "second_key": "value2"}
- {"third_key": "value3", "forth_key": "value4"}' | xargs -i python -mjson.tool {}
復(fù)制代碼 錯(cuò)誤信息是:- Traceback (most recent call last):
- File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
- "__main__", fname, loader, pkg_name)
- File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
- exec code in run_globals
- File "/usr/lib64/python2.6/json/tool.py", line 37, in <module>
- main()
- File "/usr/lib64/python2.6/json/tool.py", line 21, in main
- infile = open(sys.argv[1], 'rb')
- IOError: [Errno 2] No such file or directory: '{first_key: value, second_key: value2}'
- xargs: python: exited with status 255; aborting
復(fù)制代碼 |
|