Reputation: 23
I have a bunch of data files that are zipped (they all end in '.tagAlign.gz').
I want to move the first 100,000 lines of each file into a new file that is not zipped and keep the name of each file as it is.
I've done this for one file at a time before, but in this case I have probably 50-100 files.
I've tried looking up commands such as "rename" etc but I'm pretty new to all of this and so every answer is too complicated for me to follow.
In the case where I renamed 1 file and moved the first 100,000 lines, this is the command I ran in terminal:
gzcat nameoffile.fastq.gz | head -n 400000 > nameoffile_100k.fastq
Thanks in advance!
Upvotes: 2
Views: 269
Reputation: 103744
Your question is a little unclear, but from what I what I think you are after, you would need a loop like so:
for fn in *.gz; do
n=$(basename "$fn" .fastq.gz)
gzcat "$fn" | head -n 100000 > "$n"_100k.fastq
done
(not tested. test nondestructively please...)
Upvotes: 1