How to View and Manipulate CSV Files in Linux Using Tabview

Listen to this Post

In Linux server environments, working with CSV files is a common task. For instance, after running a script, you might need to export the results in CSV format. Typically, you can view these files using commands like `cat` or text editors like vim. However, for a more structured and visually appealing view, the CLI tool Tabview is highly recommended.

Installing Tabview

You can install Tabview using `pip` or `pipx`:

pip install tabview

Using Tabview

Assume you have a CSV file named details.csv. To view it in a tabular format, use the following command:

tabview details.csv

This will display the CSV file in a clean, organized table format. Additionally, Tabview offers useful features:
– Arrow key navigation for easy movement within the table.
– Sorting columns using the `S` (capital) and `s` (lowercase) keys.

Example CSV File

Here’s an example of a CSV file:

Name,Age,Department,Salary
Alice,30,Engineering,70000
Bob,25,Marketing,50000
Charlie,35,HR,60000
David,40,Finance,80000

Practical Commands

1. View CSV File:

tabview details.csv

2. Sort by a Specific Column:

  • Press `S` or `s` while in Tabview to sort by the selected column.

3. Extract Specific Columns:

Use `cut` to extract specific columns from the CSV:

cut -d',' -f1,3 details.csv

4. Filter Rows:

Use `awk` to filter rows based on a condition:

awk -F',' '$4 > 60000' details.csv

5. Convert CSV to JSON:

Use `csvkit` to convert CSV to JSON:

csvjson details.csv > details.json

What Undercode Say

Tabview is an excellent tool for Linux users who frequently work with CSV files. It provides a clean, interactive interface for viewing and manipulating data directly in the terminal. For advanced operations, combining Tabview with other CLI tools like awk, cut, and `csvkit` can significantly enhance productivity. Here are some additional commands to explore:

  • Count Rows:
    wc -l details.csv
    

  • Search for Specific Data:

    grep "Alice" details.csv
    

  • Convert CSV to HTML:

    csvtotable details.csv details.html
    

  • Merge CSV Files:

    csvstack file1.csv file2.csv > merged.csv
    

  • Validate CSV Format:

    csvclean details.csv
    

For more advanced CSV manipulation, consider exploring Python libraries like `pandas` or csv. Tabview is a lightweight, efficient tool that simplifies CSV handling, making it a must-have for Linux administrators and DevOps engineers.

For further reading, check out the official documentation: Tabview GitHub.

References:

Hackers Feeds, Undercode AIFeatured Image