awk capturing first sample, but not subsequent id's


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk capturing first sample, but not subsequent id's
# 1  
Old 09-20-2016
awk capturing first sample, but not subsequent id's

In the awk below the first sample MEV45 gets extracted from the html, but the subsequent MEV46 and MEV47 do not as they are not part of parse. I can not seem to add them to the code. Thank you very much @RudiC your awk is very nice Smilie.

input
Code:
{"barcodeId": "IonXpress", "barcodedSamples": {"MEV45": {"barcodeSampleInfo": {"IonXpress_007": {"controlSequenceType": "", "description": "", "externalId": "", "hotSpotRegionBedFile": "", "nucleotideType": "DNA", "reference": "hg19", "targetRegionBedFile": "/results/uploads/BED/6/hg19/unmerged/detail/LCHv2_IDP.bed"}}, "barcodes": ["IonXpress_007"]}, "MEV46": {"barcodeSampleInfo": {"IonXpress_008": {"controlSequenceType": "", "description": "", "externalId": "", "hotSpotRegionBedFile": "", "nucleotideType": "DNA", "reference": "hg19", "targetRegionBedFile": "/results/uploads/BED/6/hg19/unmerged/detail/LCHv2_IDP.bed"}}, "barcodes": ["IonXpress_008"]}, "MEV47": {"barcodeSampleInfo": {"IonXpress_009": {"controlSequenceType": "",

current output
Code:
MEV45
IonXpress_007
IonXpress_008
IonXpress_009

desired output
Code:
MEV45
IonXpress_007
MEV46
IonXpress_008
MEV47
IonXpress_009

awk
Code:
awk -F"[]\":{}, ]*" '
BEGIN   {for (n=split ("barcodedSamples,barcodeSampleInfo", T); n>0; n--) SRCH[T[n]] = n
        }
        {for (i=1; i<NF; i++) if ($i in SRCH) print $(i+1)
        }

' input

# 2  
Old 09-20-2016
How about
Code:
awk -F"[]\":{}, ]*" '
        {for (i=1; i<NF; i++) if ($i =="barcodeSampleInfo") print $(i-1) RS $(i+1)
        }

' file
MEV45
IonXpress_007
MEV46
IonXpress_008
MEV47
IonXpress_009

This User Gave Thanks to RudiC For This Post:
# 3  
Old 09-21-2016
Hello cmccabe,

Could you please try following and let me know if this helps you.
Code:
awk 'function remov(a){gsub(/[\{\":]/,X,a);print a} {if($0 ~ /MEV/){remov($0);getline;getline;remov($0);}}' RS=" "     Input_file

Output will be as follows.
Code:
MEV45
IonXpress_007
MEV46
IonXpress_008
MEV47
IonXpress_009

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 09-21-2016
Thank you both very much, works perfect Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending output of program into subsequent commands (i.e. awk/sort)

Hi, I have identified how to use command chaining as per below on a file, to capture the header of a file, as well as the line containing the C: drive. $ cat test.txt Filesystem Size Used Avail Use% Mounted on rootfs 237G 153G 84G 65% / none 237G 153G 84G ... (6 Replies)
Discussion started by: sand1234
6 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

Remove subsequent duplicate only

Hi, I've been trying to dig myself out of this, but nothing has worked out yet. I have an input like this: 1-Num1 1-Num2 2-Num3 3-Num4 1-Num5 3-Num11 2-Num11 1-Num13 1-Num16 3-Num18 4-Num19 2-Num20 1-Num22 3-Num23 (11 Replies)
Discussion started by: jamie_123
11 Replies

4. Shell Programming and Scripting

AWK sample variance

I would like to calculate 1/n In awk, I wrote the following line for the sigma summation: { summ+=($1-average)^2 } Full code: BEGIN { Print "This script calculate error estimates"; sum=0 } { sum+=$1; n++ } END { average = sum/n } BEGIN { summ=0 } { summ+=($1-average)^2 } END { print... (8 Replies)
Discussion started by: chrisjorg
8 Replies

5. Shell Programming and Scripting

awk - use fields from subsequent lines

I've run into a problem getting exactly what I want out of awk - some folks may recognize this as an output from Amazon's ec2-describe-instances: Given the following: INSTANCE i-4960f321 BLOCKDEVICE Line2Var2 TAG instance i-4960f321 Name web1 TAG instance i-4960f321... (2 Replies)
Discussion started by: colinjohnson
2 Replies

6. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

7. Shell Programming and Scripting

Capturing awk's system(cmd) output

Hi everybody, I am working on a bigger awk script in which one part is comparing the size of two files. I want to evaluate which file is bigger and then just save the bigger one. I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Discussion started by: iMeal
2 Replies

8. Shell Programming and Scripting

Grep and fetch subsequent lines also

Hi, I need to grep a pattern and fetch subsequent lines till end of the data-set. E.g., i have a file like: AA 1111 23 34 BB 45 56 78 CC 22 44 AA 2222 78 34 56 BB 22 56 67 68 23 CC 56 78 DD 33 55 77 AA 3333 46 BB 58 79 In above file i have 3-data sets where each set starts with... (6 Replies)
Discussion started by: prvnrk
6 Replies

9. Shell Programming and Scripting

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

10. Shell Programming and Scripting

How to extract a substring and append to subsequent lines

Hi all,I am really new to Shell Scripting.I have the following doubt. Let us assume the one sample file which contains the below data HEADERCARMENTRACIE1555090414 PERIOD0905090501090531 DETAIL0645693037023073836 GROUNDAV 090501 01 GROUNDAV 090502 01 TRIP 0091282542 0905084101... (5 Replies)
Discussion started by: jaligamasriniva
5 Replies
Login or Register to Ask a Question