Skip to content

Commit 22bb6e0

Browse files
committed
read from Excel to comma
1 parent 5017e5d commit 22bb6e0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

excel_to_comma.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

0 commit comments

Comments
 (0)