Hi,
I am trying to learn writing one liners using shell/awk. To begin with I want to perform the following operation using a one liner.
Scenario: A directory containing multiple fastq files with the extension .fq.gz.
Objective To automate gunzipping all the files and retain the gzipped files i.e. my directory will have *.fq.gz as well as *.fq files.
What I tried so far
I broke the problem into smaller pieces like this:
- find the files with extension *.fq.gz
- loop over the files
- pass files one by one to gunzip command
- use the option
-c
to retain the *.fq.gz files - the output files should have extension *.fq, so I split the file name by a "." to have 3 parts from the original file name i.e.
original file
test.fq.gz
after splitting
test [part 1]
fq [part 2]
gz [part3 ]
then take part 1 and concatenate ".fq" . Finally I came up with below one liner:
for i in find -name "*.fq.gz"; do gunzip -c $i > awk '{split($i,a,"."); print a[1] ".fq"}' ; done
However, it is not working, here is the error:
gunzip: find.gz: No such file or directory
gunzip: {split($i,a,"."); print a[2] ".fq"}.gz: No such file or directory
gunzip: invalid option -- e
PS: I googled a lot without much success. This may be a very easy task but I am learning to automate using one liners.
Oh .. I forgot
-k
. Oh .. I forgot-k
.No -k option. Do I have an older version?
If you use a
gunzip
with the-k
option, why not simply dogunzip -k *.fq.gz
?