C shell: Working with lists

Hello Unix Gurus,

I have:
A list of parameters that repeat (in .txt file)
Example: params.txt

Series: XYZ
Manufacturer: ...
Software Version: ...
Year made: ...

Series Series: XYZ
Manufacturer: ...
Software Version: ...
Year made: ...

Series Series: ABC
Manufacturer: ...
Software Version: ...
Year made: ...

Series Series: ABC
Manufacturer: ...
Software Version: ...
Year made: ...

Since this list is pulled from a different file, the Series XYZ or ABC, etc repeat several times along with their Manufacturer, Software version parameters (if the series is name is same, then so will be the parameters for that series).

What I need to do:
I need to make a different file pulling information from params.txt
This file will contain only ONE instance of each series along with series specific parameters. Any repetition should not be copied.

Any suggestions on how to do that will be appreciated!

homework?
awk pattern range will do here.
==>> Read lines betwwen patterns "Series:" and "Year made:"
==>> If 1st field($1) is "Series:", store Series value ($2) in a array i.e. a[$2]++
==>> Print lines if current Series value in array is equal to 1

provide sample output

I have finished school long ago, so no, it's not homework :slight_smile:
I am cataloguing differences between scanning parameters.

I am not particularly familiar with awk (or with c-shell) at this point but I have gotten the script to give me a lengthy file with all the information I need. Now I am just this one step away from having a nice descriptor file without any duplicates in it.

Thanks.

We are not supposed to give direct answers to homework kind of questions so we used to check that atleast for newcomers. So Nevermind on asking if it was homework.
I hope following will give you unique records:

awk '/Series:/,/Year made:/{if($1=="Series:"){a[$2]++;b=$2;} if(a==1) print}' inputFile

If output is not as expected, pls post the expected one.

Thank you, anurag.singh, it works perfectly. However, for each Series it only outputs Year Made, while I need it to out put 10 other parameters (for each unique series). Therefore what I get now is correct, but incomplete:

i.e
SeriesDescription T1_MPRAGE_sag
Manufacturer SIEMENS
SeriesDescription MEMPRAGE_4e_p2_1mm_iso
Manufacturer SIEMENS
SeriesDescription DIFFUSION_HighRes
Manufacturer SIEMENS

while I need something like:

SeriesDescription diff_hi_res
Manufacturer Siemens
ScannerModel Avanto
SoftwareVersion syngo MR B17
StudyDate 20030917
PulseSequence ...
FieldStrength ....
etc...

SeriesDescription T1
Manufacturer SIEMENS
ScannerModel Avanto
SoftwareVersion syngo MR B17
StudyDate 19990828
PulseSequence ...
FieldStrength ....
etc...

How to incorporate it into the awk statement mentioned above?

Thank you for all your help!

From the input given by you in post #1, I suppose output will be:

Series: XYZ
Manufacturer: ...
Software Version: ...
Year made: ...
Series: ABC
Manufacturer: ...
Software Version: ...
Year made: ...

Only one set of info to be displayed for a given "Series:"
Looks like for the set, starting pattern is: SeriesDescription
and ending pattern is not clear in your above post. Pls replace "Year made:" with the ending pattern and try.
If no good, then please post exact input format and expected output for that again.
We need to know the exact start and stop pattern for a set of data.

1 Like

thank you! The script is running and the output is in desired format. Your wonderful help is very much appreciated!