Score:0

Include header in multiple .csv file with cat linux

fk flag

I need to include a .csv header in multiple .csv files at once by switching the name to:

originalname1c.csv, originalname2c.csv, originalname3c.csv

Currently, the procedure is done as follows:

cat header.csv originalname1.csv > originalname1c.csv
cat header.csv originalname2.csv > originalname2c.csv
cat header.csv originalname3.csv > originalname3c.csv

Etc.

Is it possible to add header to multiple files as in the above example in a single command?

additional one: what if the filenames were random? keeping the rule from: anyname.csv to anynamec.csv

Score:2
hr flag

In any POSIX compliant shell

for f in *.csv; do
  cat header.csv "$f" > "${f%.csv}c.csv"
done

The ${f%.csv} construct removes the .csv extension from the expansion of $f so that you can add back c.csv to the basename.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.