Wierd results with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wierd results with awk
# 1  
Old 11-01-2007
Wierd results with awk

Hey, I'm trying to use awk for some simple file manipulations but i'm getting soem wierd results.

So i want to open up a file which looks like this:

@relation 'autoMpg'
@attribute a numeric
@attribute b numeric
@attribute c numeric
@data
-1.170815,0.257522,0.016416
-1.335653,0.30494,0.009793
-1.227306,0.300442,0.024001

and remove everything except the data, with tabs delimiting the values.

I'm using the following awk script.

gawk ' {OFS="\t"} data { print $1 $2 $3} /@data/ {data = 1} ' autoMpg-3d.arff > tmp.dat

However, no matter what value I enter for OFS, I still always get output like this:

-1.170815,0.257522,0.016416
-1.335653,0.30494,0.009793
-1.227306,0.300442,0.024001

with commas delimiting the values.

Does anyone know whats going on here?
# 2  
Old 11-01-2007
Looks like you did not specify a Field Separator just the Output Field Separator you wanted. Sorry i don't have gawk but in Awk is this close to what you were trying to do?
Code:
awk 'BEGIN {FS = ","; OFS="\t"} data { print $1, $2, $3} /@data/ {data = 1} ' ~/Desktop/datainput.txt > ~/Desktop/test.txt

OUTPUT RETURNED:
-1.170815	0.257522	0.016416
-1.335653	0.30494	    0.009793
-1.227306	0.300442	0.024001

# 3  
Old 11-01-2007
Thanks, that fixed it.

I had to use awk instead of awk though. wierd.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk parse snmp results

i run the command snmptable -v2c -c public myIP IF-MIB::ifTable the result look like this : SNMP table: IF-MIB::ifTable ifIndex ifDescr ifType ifMtu ifSpeed ifPhysAddress ifAdminStatus ifOperStatus 1 Unit: 1 Slot: 0 Port: 1... (7 Replies)
Discussion started by: wanttolearn1
7 Replies

2. Shell Programming and Scripting

Removing certain lines from results - awk

im using the code below to monitor a file: gawk '{ a += gsub("(^| )accepted( |$)", "&") a += gsub("(^| )open database( |$)", "&") } END { for (i in a) printf("%s=%s\n", i, a) }' /var/log/syslog the code is searching the syslog file for the string "accepted" and "open... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Substitute from awk results

Hi, The following awk command : asmcmd lsdg | awk '{print $13;}' | grep -i ${SID} return the following output . An Empty line + two lines contain "/" at the end of the line INDEVDATA/ INDEVFRA/ I need to remove the "/" as well as the empty line. Please advise Thanks (3 Replies)
Discussion started by: Yoav
3 Replies

4. Shell Programming and Scripting

how to display some special results with AWK

I have a file like this: AAEQGAGNQPQH,,,,160,32,,,, AAGQDYNSPLH,,712,39,,,,,, AAGREGGNTEAF,26,,,,,,,,4 AAGSPQH,,,,8,5,,,, AAKKLGQFYNEQF,4,,6,,,7,,,2 AANSGGRYNEQF,,2747,3120,,,,,, AAQGGVGGELF,,,,5,,12,36,, AAQGLAGYYEQY,,25,13,,,,,, AAQRGNEQF,510,2,,,6,,6,,76 AAQTGENSPLH,,16,16,,,,,, The... (9 Replies)
Discussion started by: xshang
9 Replies

5. Shell Programming and Scripting

Loop through awk results

I have files structured in stanzas, whose title is '', and the rest couples of 'id: value'. I need to find text within the title and return the whole stanzas that match the title. The following works: awk 'BEGIN{RS="";IGNORECASE=1}/^\/' myfileI would need to count all of the occurences, though,... (7 Replies)
Discussion started by: hermes14
7 Replies

6. Shell Programming and Scripting

Output of AWK Results

In the following line The AWK statement parses through a listing for files and outputs the results using the {print} command to the screen. Is there a way to (a) send the output to a file and (b) actually perform a cp cmd to copy the listed files to another directory? ls | awk -va=$a -vb=$b... (1 Reply)
Discussion started by: rdburg
1 Replies

7. UNIX for Dummies Questions & Answers

Env setup script givin wierd results

I have a script that setsup the environmental variables and then goes on to ftp a file . The scripts which does is as follows The script runs fine when i run it in my home dir and goes on to ftp the file.. But when the same file is run as a batch job in Control-M(a job scheduling software... (1 Reply)
Discussion started by: hareeshkumaru
1 Replies

8. Shell Programming and Scripting

need a little help with results from awk

Hi there all, I am using a line to get some replys from my PS I do ps -ef |awk '{printf $9}' But my result is 1 big line. No spaces between the lines or someting for example:... (2 Replies)
Discussion started by: draco
2 Replies

9. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies

10. Shell Programming and Scripting

store awk results in a variable

I try to get the month (of last save) and the filename into a variable, is this possible ? something like this : for month in `ls -la | awk '{print $6}'` do if ] then a=filename of the matching file cp $a /Sep fi thanks, Steffen (1 Reply)
Discussion started by: forever_49ers
1 Replies
Login or Register to Ask a Question