Skip to main content

Posts

Showing posts from 2018

Same job for multiple files

Same job for multiple files We face a common problem when we need to do the same job for multiple files in Linux environment. Example:
Extract multiple filesDelete selected multiple files where 'rm -rf *' commnad is not suitable.

It's very easy to save your time without error doing the same job.
Here is the common solution:
Algorithm/Pseudocode: Create a list of all required files which need to process same as the first file.Create a programming loopWithin the loop, apply your job for the file_variable. Also, you can add some prompt for completion of the job (timestamp) or error check or cross-check the job or parallel jobs. I have applied the algorithm using bash scripting as it is common use in Linux terminal:

#!/bin/bash
#file=$1 # for filename as input argument
# gz file list from current folder file=`ls *.gz`
# create a output folder path mkdir /tmp/myfolder
while read f do echo file is $f # extract 10 line sample from a list of .gz files zcat $f | head > /tmp/myfolder/$f.tsv d…