Sponsored Content
Full Discussion: I Am Stumped, Please Help
Top Forums Shell Programming and Scripting I Am Stumped, Please Help Post 302196162 by timj123 on Friday 16th of May 2008 10:16:19 PM
Old 05-16-2008
I Am Stumped, Please Help

I have a CSV file that I am trying to parse with awk in a table. I think I am going about this the wrong way. I can't get the awk arrays to output with a tab between them in one line. They print out vertically and I need them to print out horizontally. WHAT AM I DOING WRONG?? I want to know if it's
possible to do in awk, because it will become a function in a bigger script if this ever works out.

csv input file:
Code:
175,5  ,0,2 ,4  ,0,1 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
176,5  ,0,2 ,4  ,0,1 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
177,14 ,0,2 ,7  ,0,2 ,11 ,0,2 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
178,5  ,0,2 ,2  ,0,2 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
179,5  ,0,2 ,4  ,0,1 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
18 ,8  ,0,1 ,13 ,0,2 ,3  ,0,2 ,3  ,0,2 ,   , ,  ,   , ,  ,3  ,0,2 ,3  ,0,2 ,3  ,0,2 ,3  ,0,2 ,3
180,5  ,0,1 ,4  ,0,2 ,12 ,0,2 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
181,1  ,0,2 ,4  ,0,2 ,12 ,0,2 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3
182,14 ,0,2 ,7  ,0,2 ,3  ,0,1 ,3  ,0,1 ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,   , ,  ,3

script:
Code:
#!/usr/bin/nawk -f
BEGIN {
FS=";"
}
{
x[$2*1"-"$4*1]=x[$2*1"-"$4*1] " " $32 * 1000 + $1"-1"ORS;
x[$5*1"-"$7*1]=x[$5*1"-"$7*1] " " $32 * 1000 + $1"-2"ORS;
x[$8*1"-"$10*1]=x[$8*1"-"$10*1] " " $32 * 1000 + $1"-3"ORS;
x[$11*1"-"$13*1]=x[$11*1"-"$13*1] " " $32 * 1000 + $1"-4"ORS;
x[$14*1"-"$16*1]=x[$14*1"-"$16*1] " " $32 * 1000 + $1"-5"ORS;
x[$17*1"-"$19*1]=x[$17*1"-"$19*1] " " $32 * 1000 + $1"-6"ORS;
x[$20*1"-"$22*1]=x[$20*1"-"$22*1] " " $32 * 1000 + $1"-7"ORS;
x[$23*1"-"$25*1]=x[$23*1"-"$25*1] " " $32 * 1000 + $1"-8"ORS;
x[$26*1"-"$28*1]=x[$26*1"-"$28*1] " " $32 * 1000 + $1"-9"ORS;
x[$29*1"-"$31*1]=x[$29*1"-"$31*1] " " $32 * 1000 + $1"-10"ORS;
}
END {
for ( i in x )
printf "%-3s%-4s\n%-8s\n%-7s\n","UFC ",i,"--------",x[i]
}

output:

Code:
output:

UFC 5-2
--------
 3175-1
 3176-1
 3178-1
 3179-1

UFC 5-1
--------
 3180-1

UFC 14-2
--------
 3177-1
 3182-1

UFC 8-1
--------
 3018-1

UFC 1-2
--------
 3181-1

UFC 4-1
--------
 3175-2
 3176-2

desired output:

Code:
UFC 5-2     UFC 5-1   UFC 14-2
--------   --------   --------
 3175-1     3180-1     3177-1
 3176-1                3182-1
 3178-1
 3179-1

I hope you get the idea of the desired output, too hard to put everything in thread. I want the output to be in a table format, and sorted by UFC numbers from left to right.

Thanks in advance.
 

7 More Discussions You Might Find Interesting

1. IP Networking

httpd.conf - stumped

Have been asked to remove all images from being logged to the access_log ... where am I going wrong?<VirtualHost 123.456.789.99> ServerName www.somedomain.com.au DocumentRoot /agents/tts Redirect /wap http://somewap.com.au/traveler LogFormat "%v %h %l %u %t \"%r\" %>s %b" comonvhost... (2 Replies)
Discussion started by: Cameron
2 Replies

2. UNIX for Dummies Questions & Answers

RegEx question has me stumped

Hi All, I'm fairly new to Regular Expressions, and have made some decent progress, but this one has me scratching my head. I'm trying to match the class name in my scripts as shown in the examples below. Any ideas? Thanks! -Mark :: Looking for a regex to match the red text :: import... (7 Replies)
Discussion started by: tolmark
7 Replies

3. Shell Programming and Scripting

Stumped

Hi, I'm pretty new to UNIX shell scripting and need some help. We have an Informatica interface that dumps any files that have errors into a directory. I need to check that directory for any of up to 9 files that might be in it and run a specific process for each file found. Here's what I... (3 Replies)
Discussion started by: JeffR
3 Replies

4. Shell Programming and Scripting

perl replace command, stumped!

Ok, I stole some code from a program that takess a hash of a password from PasswdMD5 and replaces it in the /etc/shadown file on a linux system. I run his program and it's fine. Well I took the same code and put it in another program that won't ask for prompgx and such and this code won't work:... (2 Replies)
Discussion started by: benefactr
2 Replies

5. Shell Programming and Scripting

Command not found in shell script - stumped for 4 days

Hello, I like to begin with :wall:.. literally... It has been 4 days and I have no idea how to fix it. Environment - AIX 5.3 I wrote a script to call on ssh to log into another box via PKA to do something else. If I run the script on the terminal, it works 100%. If the SAP customised... (11 Replies)
Discussion started by: plonkagain
11 Replies

6. Shell Programming and Scripting

Stumped on simple BASH Script

Hello All, First and foremost, if I have posted this question in the wrong forum/section, I apologize. Okay so here is my dilemma. I have written a BASH script that automatically restarts a tomcat on a given server. That part was simple enough. However, now I would like to not only restart... (14 Replies)
Discussion started by: UNM_Lobo
14 Replies

7. UNIX for Dummies Questions & Answers

Stumped .. is this a command line arg?

I need a bit of explanation: LogFile=${LOGS_DIR}/${1}_$$ I know: - LOGS_DIR is an environment variable - $$ is the PID ... but what is ${1} ?? Is it another method to access a command line variable, or the job name? Thanks! Jon (3 Replies)
Discussion started by: jdorn001
3 Replies
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy