export all tables of sqlite3 database as CSV

Поделиться
HTML-код
  • Опубликовано: 27 июн 2024

Комментарии • 1

  • @OfficialOrangeio
    @OfficialOrangeio  17 дней назад

    #!/bin/bash
    # Prompt for the path to the SQLite database file
    read -p "Enter the path to your SQLite database file: " DB_FILE
    # Check if the file exists
    if [[ ! -f "$DB_FILE" ]]; then
    echo "File not found!"
    exit 1
    fi
    # Get the list of tables in the database
    TABLES=$(sqlite3 "$DB_FILE" ".tables")
    # Loop through each table and export it to a CSV file
    for TABLE in $TABLES; do
    # Define the output CSV file name
    CSV_FILE="${TABLE}.csv"
    # Export the table to the CSV file
    sqlite3 "$DB_FILE"