27 lines
558 B
Bash
Executable File
27 lines
558 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Input file
|
|
FILE=$1
|
|
|
|
# Check if the file is provided
|
|
if [ -z "$FILE" ]; then
|
|
echo "Usage: $0 <file>"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if the file exists
|
|
if [ ! -f "$FILE" ]; then
|
|
echo "Error: File '$FILE' not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Find rows containing a comma and extract the first segment before '-'
|
|
while IFS= read -r line; do
|
|
if [[ $line == *,* ]]; then
|
|
# Extract the first segment before '-'
|
|
first_segment=$(echo "$line" | cut -d'-' -f1 | xargs)
|
|
echo "Line with comma: '$line' | First segment: '$first_segment'"
|
|
fi
|
|
done < "$FILE"
|
|
|