Hi,
I'm having trouble with a script to copy one line out of multiple files in a directory and copy to a file called test. I've tried the code below but it copies one line out of the first file multiple times not one line out of all the files. Would someone help? I'm very new to all this.
Many thanks,
Bob
#!/bin/bash
for i in *.CSV
do
sed -n '10p' *.CSV >> test
done
These are two of the files in the directory I want to copy line 10 from and copy to file "test":
574 McClain.0101.CSV 574 McClain.0103.CSV
when I run the script with the ${i} included, the file "test" is generated but is empty and Unix responds with:
sed: 574: No such file or directory
sed: McClain.0101.CSV: No such file or directory
sed: 574: No such file or directory
sed: McClain.0103.CSV: No such file or directory
Yes, I removed file "test" and ran the script. There are 12 files in the sandbox directory. When the file "test" is generated again from the script the results are 24 lines:
SUBJECT ID:b2425 c57 2-6mg low Fe
SUBJECT ID:b2428 c57 2-6mg low Fe
SUBJECT ID:b2389 c57 2g hi Fe
SUBJECT ID:b2390 c57 2g hi Fe
SUBJECT ID:b2391 c57 2g hi Fe
SUBJECT ID:b2392 c57 2g hi Fe
SUBJECT ID:b2431 c57 2-6 mg low Fe
SUBJECT ID:b2432 c57 2-6mg low Fe
SUBJECT ID:b2393 c57 2g/kg hi Fe
SUBJECT ID:b2394 c57 2g/kg hi Fe
SUBJECT ID:b2433 c57 2-6 mg low Fe
SUBJECT ID:b2434 c57 2-6 mg low Fe
SUBJECT ID:b2425 c57 2-6mg low Fe
SUBJECT ID:b2428 c57 2-6mg low Fe
SUBJECT ID:b2389 c57 2g hi Fe
SUBJECT ID:b2390 c57 2g hi Fe
SUBJECT ID:b2391 c57 2g hi Fe
SUBJECT ID:b2392 c57 2g hi Fe
SUBJECT ID:b2431 c57 2-6 mg low Fe
SUBJECT ID:b2432 c57 2-6mg low Fe
SUBJECT ID:b2393 c57 2g/kg hi Fe
SUBJECT ID:b2394 c57 2g/kg hi Fe
SUBJECT ID:b2433 c57 2-6 mg low Fe
SUBJECT ID:b2434 c57 2-6 mg low Fe
Thanks again,
Bob
---------- Post updated at 01:22 PM ---------- Previous update was at 01:19 PM ----------
I figured it out. It was a typo on my part. The problem is solved.
Thanks for all your help and patients with a "nubee"