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...
# 8  
Old 06-17-2009
Dear Rakeshawasthi,

I tried the below code in Bash shell, but i am getting error as "syntax error near unexpected token '$'do\r'' .

kindly clarify.....


Code used:

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



Thanks in advance
vasnath

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

Dear panyam,

i have used the below code, which you referred....

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


I am getting the output, same as input. It is working just like cat command.

Kindly clarify......
Vasanth
# 9  
Old 06-17-2009
sorry there was a typo .
Code:
awk -F"[{=}]" '!($1 in a) {key[++key[0]]=$1} {a[$1]=a[$1]" "$2;next} END { for(i=1;i<=key[0];i++){ print key[i] a[key[i]]}}' input_file_name.txt |  sed '/^[ ]*$/d'

# 10  
Old 06-17-2009
Yes, thanks a lot, Panyam....
# 11  
Old 06-17-2009
It works for me.
have you replaced the testfile with your input file name..
tell me how can I replicate the error?
# 12  
Old 06-17-2009
One more thing, panyan i need a scritp to remove the space before and after the operator like( +, -, ||, &&).

Ex :

Input file

apple + manago

mango && fresh + apple fresh || fruit


Desired output:

apple+manago

mango&&fresh+apple fresh||fruit


Note: betwee the desired operator space should be removed, between words do not remove space.

Thanks in advance,
Vasanth

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

Dear rakeshawasthi ,

I have used cygwin bash shell.

I think your code, u r executing in KSH.


code used :

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


Error message:
syntax error near unexpected token '$'do\r''

Thanks
vasanth

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

Dear rakeshawasthi ,

I have used cygwin bash shell.

I think your code, u r executing in KSH.


code used :

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


Error message:
syntax error near unexpected token '$'do\r''

Thanks
vasanth
# 13  
Old 06-17-2009
Yes .
# 14  
Old 06-17-2009
Ok.rakeshawasthi ,

do you answer for my new post, about removing spaces inbetween operators

Thanks in advance
Vasanth
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