I have six CSV files I want to manipulate with sed
sed -i -e "1d" 1.csv 2.csv 3.csv 4.csv 5.csv 6.csv
or
sed -i -e "1d" *csv
but when running any of these commands only 1.csv is modified. However, sed renames the original of 2-6.csv (the timestamp of the backup file remain unchanged) to 2.csv-e and so on and create a new file 2.csv but this new file is identical to 2.csv-e (and diff:ing 2.csv and 2.csv-e returns no differences) (diffing 1.csv and 1.csv-e lists some changes).
How do I make sed accept more than one file as input?
This is on OS X.
The OSX sed
man page says
Sed Addresses
An address is not required, but if specified must be a number (that counts input lines cumulatively across input files), a dollar (``$'') character that addresses the last line of input, or a context address (which consists of a regular expression preceded and followed by a delimiter).
So, you need a different approach
for file in 1.csv 2.csv 3.csv 4.csv 5.csv 6.csv; do
sed -i -e "1d" "$file"
done
With GNU-sed, you can use -s:
sed -i.bak -se "1d" {1..6}.csv
(The {1..6} construct works at least in bash.)
The manpage of sed says:
-s, --separate
consider files as separate rather than as a single continuous long stream.
and it works for me, including the in-place command and generation of .bak files. But I don't know for MacOS. Try with testdata first or read the man page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With