嘿伙计们,所以我有这个数据库:
id | item_name | number_of_store| store_location|
+----+---------+-------------------+-------------+
| 3 | margarine | 2 | QLD |
| 4 | margarine | 2 | NSW |
| 5 | wine | 3 | QLD |
| 6 | wine | 3 | NSW |
| 7 | wine | 3 | NSW |
| 8 | laptop | 1 | QLD |
+----+---------+-------------------+-------------+
我得到了我想要的结果,使用与SQLite3不同的语法如下:
id | item_name | number_of_store| store_location|
+----+---------+-------------------+-------------+
| 3 | margarine | 2 | QLD |
| 4 | margarine | 2 | NSW |
语法是:
sqlite3 store.sqlite 'select item_name,number_of_store,store_location from store where item_name = 'margarine'> store.txt
但是当我将其保存到 TXT 时,我得到了
3|margarine|2|QLD
4|margarine|2|NSW
但是我在 TXT 中所需的输出是
3,margarine,2,QLD
4,margarine,2,NSW
我想我应该使用 SED 但不太确定该怎么做
我试过
'|sed 's/|//g' |sed 's/|//g'|sed 's/^//g'|sed 's/$//g'
但是结果只会删除"|"我不太确定如何将其更改为",">
虽然你应该sql本身,但根据您的要求,你可以使用以下sed
。
awk '{gsub("|",",")} 1' Input_file
或sed
:
sed 's#|#,#g' Input_file
如果您想将输出保存到Input_file本身,请使用sed -i.bak
选项,它将备份Input_file并将输出保存到Input_file本身。