This question already has answers here:
How to split a string into an array in Bash?
(24 answers)
How do I split a string on a delimiter in Bash?
(37 answers)
Closed 3 years ago.
I am new to shell script and I have started it today itself. Can anyone tell me how to store and retrieve the output of this command:
cat /proc/cpuinfo | grep "MHz" | awk '/cpu MHz/ {print $4}'
This command returns just four decimal numbers but I am struggling to store these four numbers.
I have tried to store them in array but it has not been fruitful for me. Please help!!
Related
This question already has answers here:
How to delete the first column ( which is in fact row names) from a data file in linux?
(5 answers)
Unix , Delete first column using awk
(3 answers)
Closed 1 year ago.
This is output of speedtest-cli. I just need the specific values without the Download: and Upload: headers.
How can I do this?
Download: 8.34 Mbit/s
Upload: 0.69 Mbit/s
You can print only 2nd "word" using awk
awk '{print $2}'
This question already has answers here:
How to use sed/grep to extract text between two words?
(14 answers)
Closed 2 years ago.
I have a string that looks like this:
RG="#RG\tID:HS2000-1015_160.7\tDS:ADNI_1380^LP6005117-DNA_G04^ADNI_WGS\tLB:LP6005117-DNA_G04\tPL:illumina\tPU:HS2000-1015_160.7\tSM:ADNI_1380"
I want to extract everything after ID: and before first the \t
and get HS2000-1015_160.7 as a result. I would like a one-liner if possible.
code I tried:
echo ${RG} | grep -oP "(?<=ID:)[^"\t"]*"
which gives me HS2000-1015_160.7\
Try:
sed 's/.*ID://;s/\\t.*//'
s/.*ID:// remove everything in front and including ID:
s/\\t.*//' remove everything after and including \t characters.
This question already has answers here:
How to add new line using sed on MacOS?
(3 answers)
Closed 2 years ago.
I'm trying to replace each comma with a new line.
e.g. when I do the following
echo abc,wer | sed 's/\,/\n/g'
I hope to get
abc
wer
However, I got
abcnwer
What did I do wrong?
Based on #MarkSetchell answer above, the below works.
echo abc,wer | tr , '\n'
This question already has answers here:
Extract specific columns from delimited file using Awk
(8 answers)
Closed 4 years ago.
I am parsing the csv file using while loop in shell script which has data in below format
ba04ba54,1234,MMS,"[""some"", ""somet2"", ""somet""]",21556,48834
code:
while IFS=, read -r id mvid conkey values cretime modified;
do
echo $id,$mvid,$conkey,$values,$cretime,$modified
but values is assigned with
"[""some""
instead of
"[""some"", ""somet2"", ""somet""]" how to achieve this using shell script
Could you please try following.
awk 'match($0,/\"\[\".*\]\"/){print substr($0,RSTART,RLENGTH)}' Input_file
This question already has answers here:
Grep inside all files created within date range
(3 answers)
Closed 5 years ago.
I have a file with timestamps and I want to grep it so that I can see the lines matching 12:30:00 - 12:32:00 . I know that in bash there is the {0..2} for doing something similar but I dont know in grep how to do it?
At the moment I am doing grep 2015-01-12 12:3{0..2} but it doesnt work?
you can use the following for this.
grep '2015-01-12 12:3[0-2]'
or
grep '2015-01-12 12:3[0,1,2]'
I hope it helps.