This question already has answers here:
Parsing JSON with Unix tools
(45 answers)
Closed 4 years ago.
I have this input
[{"email":"etu#etu"},{"email":"hg"},{"email":"ismail"}]
and I want to extract only the value on the email using bash.
Simply with jq:
echo '[{"email":"etu#etu"},{"email":"hg"},{"email":"ismail"}]' | jq -r '.[].email'
The output:
etu#etu
hg
ismail
I recommend you use some unix tool for this and invoke it in your bash process.
Check this out: json command line processor
You probably want to investigate this one and you'll be probably good to go.
Related
This question already has answers here:
What is a simple explanation for how pipes work in Bash?
(11 answers)
Closed last year.
I know for example: ls -all | grep Hello means to search all files containing Hello. What is the definitive definition of the | command? What exactly is going on here with |?
pipe; send whatever we get from the left side to the right side: (https://www.makeuseof.com/what-are-linux-metacharacters/) I would also take a look at the gnu bash manual: https://www.gnu.org/software/bash/manual/bash.html and check specifically the 3.2.3 Pipelines for more in depth information
This question already has answers here:
Reading java .properties file from bash
(13 answers)
Closed 4 years ago.
I have a property s3Path=s3a://myBucket in a file s3-apps.properties
Currently the path to a S3 is hardcoded in my bash script:
thePath="s3a://myBucket/myApp"
I want to get the property from the file instead and concatenate it with /myApp
So I'm getting path to the file like this:
file="/apps/properties/various/s3-apps.properties"
But how do I get the property and concatenate it to construct a path?
I guess that it should be something like this but it did not work for me:
thePath="s3a://{$file.s3Path}/myApp"
Non of the answers from the "Duplicate" helped me in understanding an solving my question. But the #cody answer below was correct and helped.
If you're using GNU grep, the following would work:
$ s3path=$(grep -Po '(?<=s3Path=).+$' "$file")
$ echo $s3path
s3a://myBucket
This question already has answers here:
How can I remove the extension of a filename in a shell script?
(15 answers)
Closed 5 years ago.
I have hundreds files need to loop through for an analysis using a bash script. One step I need to do is to split a long string and cat it as an output name. For example, suppose I have one string such like:
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final.bam
What I wanted is to rename it as two output file names such as:
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R1.fastq
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R2.fastq
The only changes are removing .bam from the original and cat _R1.fastq and _R2_fastq. Does somebody know how to realize it using bash commands?
somefile=blahblahblah.final.bam
foo "$somefile" "${somefile%.*}_R1.fastq" "${somefile%.*}_R2.fastq"
This question already has answers here:
Shell command to retrieve specific value using pattern
(3 answers)
Closed 8 years ago.
I have file test.txt contains the following
AA=testing
BB=help
CC=hello
How can i make a bash script that will get each value and assign to a new variable?
#!/bin/bash
var1=testing
var2=help
var3=hello
thanks for the help
First of all a = value is not correct syntax in shell. In shell the spaces are important.
When you have a valid file, you can use the eval function to evaluate that file as a string, or simply source it.
This question already has answers here:
Using getopts to process long and short command line options
(32 answers)
Closed 8 years ago.
I want to write a bash shell script, it can accept parameters, and the parameter has prompt, example,
./test.sh --version=1.0
value 1.0 is the real parameter for my shell, and --version= is the prompt
is there any easy way to do it like this?
You should have have a look at man(1) getopt.
Depending what you mean by "easy" - using getopts should work. A bit of typing, but... Here are some examples to get you started:
http://rsalveti.wordpress.com/2007/04/03/bash-parsing-arguments-with-getopts/
How do I parse command line arguments in Bash?
http://spin.atomicobject.com/2011/03/30/parsing-arguments-in-bash-with-getopts/