File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # Check if filename is provided as argument
4
+ if [ $# -eq 0 ]; then
5
+ echo " Usage: $0 <filename.xlsx>"
6
+ exit 1
7
+ fi
8
+
9
+ # Check if the file exists
10
+ if [ ! -f " $1 " ]; then
11
+ echo " File not found: $1 "
12
+ exit 1
13
+ fi
14
+
15
+ # Convert Excel (.xlsx) to CSV
16
+ csv_file=$( xlsx2csv " $1 " | head -n 1)
17
+
18
+ # Using awk to extract the first column and join lines with commas
19
+ awk -F ' ,' ' {print $1}' " $csv_file " | paste -s -d ' ,' -
20
+
21
+ # Explanation of commands:
22
+ # 1. xlsx2csv "$1" | head -n 1: Converts the Excel file to CSV format and gets the first line (header)
23
+ # 2. awk -F ',' '{print $1}' "$csv_file": Extracts the first column using comma (,) as the delimiter
24
+ # 3. paste -s -d ',' -: Joins the lines using comma (,) as the delimiter
25
+ # - -s: Concatenate all lines
26
+ # - -d ',': Use comma as the delimiter
27
+ # - -: Read from standard input (output of awk)
28
+
29
+ # Example usage:
30
+ # ./process_excel.sh /path/to/your/excel_file.xlsx
You can’t perform that action at this time.
0 commit comments