Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How would I display the first line of all files matching a glob? [closed]
Closed as unclear by Alexei on May 10, 2024 at 06:18
This question cannot be answered in its current form, because critical information is missing.
This question was closed; new answers can no longer be added. Users with the reopen privilege may vote to reopen this question if it has been improved or closed incorrectly.
My use case is a collection of CSV files, each with header row. What I want to know is what subset(s) of them are "union compatible", although I also want matching column names before stacking these tables.
1 answer
The first line of a file is head -1
. But you probably also want the file name. So something like:
for file in glob
do
first_line="$(head -1 "$file")"
printf "%s: %s\n" "$file" "$first_line"
done
Where glob
above is something like *.csv
or whatever.
1 comment thread