I have a folder called /home/myusername/originalFiles where I got tons of large *.gz files. Inside this folder and its subfolders we got also tons of large *.gz files, too. Without deleting or modifying any of the *.gz files I need:
a) For each file f in /home/myusername/originalFiles (and subfolders), expand it,
b) Extract the first 200 lines from the expanded f
c) Convert that "200 lines" file from b) into a gz file again
d) Copy the "gzipped 200 lines" file from c) into another folder called /home/myusername/newSampleFiles but respecting the folder structure and name at /home/myusername/originalFiles. So, if the original file f was in a subfolder like /home/myusername/originalFiles/year2020 then the respective "gzipped 200 lines" file from c) must be in /home/myusername/newSampleFiles/year2020 and using the same name and extension of the original file in /home/myusername/originalFiles
e) Do not keep any expanded file obtained at a)
f) Do this only using Linux cmds
I tried
find . -type f -name "*.gz" -print | xargs -I@ sh -c 'head -n200 @ > /home/myusername/newSampleFiles/@'
but I got the error message:
/home/myusername/newSampleFiles/./someFile.txt.gz: No such file or directory
question from:
https://stackoverflow.com/questions/65889329/exracting-200-first-lines-from-a-zip-file-and-creating-this-file-into-a-differen 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…