shell script|November 24, 2017|1 min read

Shell script to extract single file from a bunch of jar files

Shell script to extract single file from a bunch of jar files

Problem Statement

I have a bunch of jar files lying in a folder. Lets name it /Users/labuser/jars

Each jar file has a manifest file in META_INF/MANIFEST.MF
I have to read each MANIFEST.MF file and get some information from it. So, instead of extracting whole jar, one by one is a tedius thing.

What I want

I want to extract that file in a folder whose name can be as of jar file.

Unzip command to extract a jar file

Following command can be used to unzip a complete jar file:

unzip <path of jar file>

If you want to unzip files to a particular folder

unzip <path of jar file> -d <path of target folder>

Note: if the target folder does not exists, it will be created

If you want to unzip only particular files

unzip <path of jar file> <path of file inside jar file>

If you want to unzip only particular files in a particular folder

unzip <path of jar file> <path of file inside jar file> -d <target folder>

Conclusion

That is all. Combine these, and you are done.

Shell script I used to solve this

for myfile in `ls /Users/labuser/jars` ; do unzip ../$myfile META-INF/MANIFEST.MF -d $myfile; done

Related Posts

Drupal 7&#58; How to save a node programmatically and add an image field from a public URL

Drupal 7&#58; How to save a node programmatically and add an image field from a public URL

Note: I have public URLs of these images, which I want to save. return…

Kubernetes - How to Configure Docker Repository to Pull Image and Configure Secret

Kubernetes - How to Configure Docker Repository to Pull Image and Configure Secret

Introduction In most of cases, you are not pulling images from docker hub public…

Docker Push&#58; How to push your docker image to your organization in hub.docker.com

Docker Push&#58; How to push your docker image to your organization in hub.docker.com

Tag the image, by seeing its image id, from docker images command docker tag 04d…

Azure Storage Blob - How to List Blob, Download Blob from Azure Storage container in Python (pypy libs)

Azure Storage Blob - How to List Blob, Download Blob from Azure Storage container in Python (pypy libs)

Introduction In this tutorial we will see: How to instantiate different classes…

ReactJS - How to pass method to component and how to pass arguments to method

ReactJS - How to pass method to component and how to pass arguments to method

Introduction In the ReactJS project, you are having aa parent component and a…

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Introduction I had to write a CICD system for one of our project. I had to…

Latest Posts

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Introduction In this post we will see following: How to schedule a job on cron…

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

Introduction There are some cases, where I need another git repository while…

How to Fetch Multiple Credentials and Expose them in Environment using Jenkinsfile pipeline

How to Fetch Multiple Credentials and Expose them in Environment using Jenkinsfile pipeline

Introduction In this post, we will see how to fetch multiple credentials and…

Jenkins Pipeline - How to run Automation on Different Environment (Dev/Stage/Prod), with Credentials

Jenkins Pipeline - How to run Automation on Different Environment (Dev/Stage/Prod), with Credentials

Introduction I have an automation script, that I want to run on different…

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Jenkinsfile - How to Create UI Form Text fields, Drop-down and Run for Different Conditions

Introduction I had to write a CICD system for one of our project. I had to…

Java Log4j Logger - Programmatically Initialize JSON logger with customized keys in json logs

Java Log4j Logger - Programmatically Initialize JSON logger with customized keys in json logs

Introduction Java log4j has many ways to initialize and append the desired…