Script - Filter data - repeated loop - Help needed...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script - Filter data - repeated loop - Help needed...
# 1  
Old 06-16-2009
Script - Filter data - repeated loop - Help needed...

Dear Friend,

I need a help for the below problem.. Can anyone suggest me to do...



Input file data:

rule {
name=mainrule
filt=pos
loc {
x=right + 660
y=top - 3100
}
object_kind= DRAW
object_name= pen
sym_name_expr= 123
anchor= 0
pol= 1
rot= 0
angle=0
mirror=no

text {
x_size=0
y_size=0
width=0
}
}



rule {
name=rule2
filt=neg
loc {
x=890
y=100
}
object_kind= shape
object_name= ink
sym_name_expr= 321
anchor= 1.5
pol= 0
rot= 90
angle=90
mirror=yes

text {
x_size=1
y_size=1
width=1
}
}



In the above file, the loop and sub-loop has variables and values. Now i need the output as for all variables only the values, like a report.



Required output:

Rule
Name mainrule rule2
Filt pos neg
Loc
X right + 660 890
Y top - 3100 100
Object_kind DRAW shape
Object_name pen ink
sym_name_expr 123 391
anchor 0 1.5
pol 1 0
rot 0 90
angle 0 90
mirror no yes
text
x_size 0 1
y_size 0 1
width 0 1



I have tried in awk but, loop-wise how to filter the data's. Smilie

Thanks in Advance,
Vasanth

-----Post Update-----

The below problem solution required.....

-----Post Update-----

Anybody have answer for my Question

-----Post Update-----

Anybody have answer for my Question
# 2  
Old 06-16-2009
Code:
awk -F"[{=}]" '{ a[$1]=a[$1]" "$2;next } END { for(i in a) print i  a[i] }' input_file.txt

check the forum to print the array elements in order, since the order of the array elements wont be the same as the order in which we processed.
# 3  
Old 06-16-2009
Thanks but....

Dear Panyam,

The code given by u, is scanning file and giving output by the repeated lines.

The required output should be variable should remain and the values should come in the same row..

Thanks in advance
Vasanth
# 4  
Old 06-16-2009
This was really challenging Vasanth...
Code:
test=testfile
count=1
for i in `awk '{FS="[{}= \t]+";print $1}' $test`
do
   a=`grep -w $i $test | awk '{FS="[{}= \t]+";for (i=2;i<=NF;i++)print $i}' | xargs`
   if [[ $i == "rule" && $count -ne 1 ]];then
      break
   fi
   echo $i $a
   (( count = $count + 1 ))
done

# 5  
Old 06-16-2009
Code:
awk -F"[{=}]" '!($1 in A) {key[++key[0]]=$1} {a[$1]=a[$1]" "$2;next} END { for(i=1;i<=key[0]/2;i++){ print key[i] a[key[i]]}}'  | sed '/^[ ]*$/d'  input_file.txt

Above worked fine for me
here is the output i got for your input file
Code:
rule
name mainrule rule2
filt pos neg
loc
x right + 660 890
y top - 3100 100
object_kind  DRAW  shape
object_name  pen  ink
sym_name_expr  123  321
anchor  0  1.5
pol  1  0
rot  0  90
angle 0 90
mirror no yes
text
x_size 0 1
y_size 0 1
width 0 1

# 6  
Old 06-16-2009
Is it possible in csh...

Dear rakeshawasthi,

Thanks. Its look like bash shell script.

Is it possible using CSH.

Thanks
Vasanth
# 7  
Old 06-16-2009
I think it will work...try Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help - manipulate data by columns and repeated

Hello good afternoon to everyone. I'm new to the forum and would like to request your help in handling data. I hope my English is clear. I have a file (Dato01.txt) to contine the following structure. # Col1 - Col2 - Col3 - Col4 Patricia started Jun 22 05:22:58 Carolina started Jun... (5 Replies)
Discussion started by: kelevra
5 Replies

2. Shell Programming and Scripting

Calculate average for repeated ID within a data

I have an awk script that gives the following output: Average end-to-end transmission delay 2.7 to 5.7 is 0.635392 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.66272 seconds Average end-to-end transmission delay 2.1 to 5.1 is 0.691712 seconds Average end-to-end transmission... (4 Replies)
Discussion started by: ENG_MOHD
4 Replies

3. Shell Programming and Scripting

How do I put data piped to my script into an array for repeated processing

Hi folks, Sorry for something I'm sure was answered already, I just could not find it in a search of the forums. I am trying to build a script that eats a config file as: cat file.cnf | ConProcess.shWhat I want to do inside the script is: !#/usr/bin/bash # captured piped cat into an... (6 Replies)
Discussion started by: Marc G
6 Replies

4. UNIX for Dummies Questions & Answers

Command line / script option to filter a data set by values of one column

Hi all! I have a data set in this tab separated format : Label, Value1, Value2 An instance is "data.txt" : 0 1 1 -1 2 3 0 2 2 I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for... (1 Reply)
Discussion started by: gnat01
1 Replies

5. Shell Programming and Scripting

How to filter required data from file using bash script?

Hi All , I have one file like below , Owner name = abu2-kxy-m29.hegen.app Item_id = AX1981, special_id = *NULL*, version = 1 Created = 09/01/2010 12:56:56 (1283389016) Enddate = 03/31/2011 00:00:00 (1301554800) From the above file I need to get the output in the below format ,i need... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

6. Shell Programming and Scripting

Filter data in Excel sheet using Shell Script

Hi, I have an excel sheet which has 100000 records. All these records are having 3 columns each with the last column as "Y" or "N". I would like to filter those records which has the value "Y". Can you please let me know how to proceed with that? Thanks in advance. -Sri ----------... (8 Replies)
Discussion started by: bhanusri83
8 Replies

7. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

8. Shell Programming and Scripting

repeated column data filter and make as a row

I need to get the output in row wise for the repeated column data Ex: Input: que = five ans = 5 que = six ans = 6 Required output: que = five six ans = 5 6 Any body can guide me?"""""" (2 Replies)
Discussion started by: vasanth_vadalur
2 Replies

9. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

10. Shell Programming and Scripting

NEED HELP PLZ! While Loop script needed!

PLZ Help us. I need to write a "while loop" script in borne shell to go into the /tmp directory every second and update me with the size of every file in the temp directory. My boss sprung this on me today and I have to have the script done by tomorrow. I can't loose my job, cause my wife and I... (1 Reply)
Discussion started by: scoobydoo
1 Replies
Login or Register to Ask a Question