C shell: Working with lists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting C shell: Working with lists
# 1  
Old 01-06-2011
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!
# 2  
Old 01-06-2011
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
# 3  
Old 01-06-2011
provide sample output
# 4  
Old 01-07-2011
Quote:
Originally Posted by anurag.singh
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
I have finished school long ago, so no, it's not homework Smilie
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.
# 5  
Old 01-07-2011
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:
Code:
awk '/Series:/,/Year made:/{if($1=="Series:"){a[$2]++;b=$2;} if(a[b]==1) print}' inputFile

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

Last edited by anurag.singh; 01-07-2011 at 11:39 AM..
# 6  
Old 01-07-2011
Quote:
Originally Posted by anurag.singh
We are not supposed to give direct answers to homework kind of questions so we used to check that atleast for newcomes. So Nevermind on asking if it was homework.
I hope following will give you unique records:
Code:
awk '/Series:/,/Year made:/{if($1=="Series:"){a[$2]++;b=$2;} if(a[b]==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!
# 7  
Old 01-07-2011
From the input given by you in post #1, I suppose output will be:
Code:
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.

Last edited by anurag.singh; 01-07-2011 at 12:05 PM..
This User Gave Thanks to anurag.singh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

• Write a shell script that upon invocation shows the time and date and lists all the logged-in user

help me (1 Reply)
Discussion started by: sonu pandey
1 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

C-Shell!! Please help...cannot get it working...

Dear Friends, I am trying to get a script in c-shell working but no way! I don't know why but on my mac was working and now on linux is not! Basically the script should accept a root_file_name and work in batch on files. This is the script: #!/bin/csh -fn setenv IMAGIC_BATCH 1 ... (3 Replies)
Discussion started by: Mandrake83
3 Replies

4. Shell Programming and Scripting

Shell script that lists files with different owner than the folder

Hello, I'm trying to write a script which is listing files based on different preferences, like filetype or permissions. All is fine, except for one: I want to list files in /home which has a different owner than the home directory it is in. Here is an example: /home/UserA is the directory, and... (10 Replies)
Discussion started by: Zwiebi
10 Replies

5. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

6. Shell Programming and Scripting

Editing lists of integers in 1d files with bash shell

Hi, I need a script that will: 1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this: 22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Discussion started by: ac130pilot
1 Replies

7. Shell Programming and Scripting

Which Shell I'm working?

Hi, I'm using FreeBSD 6. I want to know which Shell I'm using. So I gave the command: -sh-3.1$ ps -p $$ PID TTY TIME CMD 15547 pts/1 00:00:00 sh Which shell is "sh"? Is it C Shell or Bourne Shell or Korn Shell? Also, are Bourne & Korn shell one and the same or are... (4 Replies)
Discussion started by: freephoneid
4 Replies

8. Shell Programming and Scripting

if -z not working in SH shell

Hello all, Any idea how to check whether a variable holding null value or not. if -z option works fine in bash, where as it is not working in sh. bash-3.00$ sh $ TEST= $ if ; then > echo "Null" > else > echo "Not null" > fi sh: test: 0403-004 Specify a parameter with this command.... (2 Replies)
Discussion started by: rijeshpp
2 Replies

9. Shell Programming and Scripting

Help with a shell script to concatenate lists together

Below is a description of what im trying to achieve: Write a shell script to concatenate lists together, and output the resulting list. Do not include any argument that is a sub-list of the entire list. (The script will clean the list of any redundant items.) You must preserve the original order... (1 Reply)
Discussion started by: rfourn
1 Replies

10. Shell Programming and Scripting

Check lists for Unix Shell Programming

Hi all, Can anyone provide me any checklists or a list of steps I should follow before executing my scripts. Could also tell me if there are any other standards to be followed while shell programming like naming conventions for variables etc. Your help would be much appreciated. Regards,... (2 Replies)
Discussion started by: srikanth_ksv
2 Replies
Login or Register to Ask a Question