1. Add quotation marks and commas

sed -i 's/^/"&/g; s/$/&",/g' filename
Copy the code

2. Remove the comma at the end of the last line and add characters to the first and last lines

sed -i "\$s/,//g; 1s/^/{sn:{\$in:[&/;\$s/$/&]}}/" filename
Copy the code

3. There is an extra ^M in the file after sed replaces the file

sed -i 's/^M//g' filename 
Copy the code

Note: The input for ^M in Linux is Ctrl + V, then Ctrl + M

4. Export the database

/mongoexport --authenticationDatabase=admin -u user -p password -d library -c table --type CSV -o /home/test.csv -f field1, the field2 --queryFile=/home/test.txt
Copy the code