AWK Programming Problem


 
Thread Tools Search this Thread
Top Forums Programming AWK Programming Problem
# 15  
Old 03-02-2011
In my suggestion I used FS=\| and OFS=\| (not FS=| and OFS=| ) and also $0=$0 and not $0-$0 and I get:
Code:
1586|80100001|0389|70707|49121|5990|25002|41401|515|4019|56210|56999|||||||||||||||||||||||||||||||1|2|1|2|1|1|2|2|2|1||||||||||||||||||||||||||||||

Don't you?
# 16  
Old 03-02-2011
Hi Scrutinizer

Yes, I'm getting that results,

for the work code all I should have is a total of 30 fields, the results you are getting is a total of 40 fields.

PHP Code:
1586|80100001|0389|70707|49121|5990|25002|41401|515|4019|56210|56999|||||||||||||||||||||||||||||||1|2|3|4|5|6|7|8|9|1|||||||||||||||
||||||||||||||| 
The output should be:

PHP Code:
1586|80100001|0389|70707|49121|5990|25002|41401|515|4019|56210|56999|||||||||||||||||||||1|2|1|2|1|1|2|2|2|1||||||||||||||||
||||| 
Same with the pri code fields there should only be a total of 30 fields.

Do I still have some thing wrong?

THX, gator5242
# 17  
Old 03-02-2011
Just replace the 30's with 20's in my solution, or experiment with the right number.

Last edited by Scrutinizer; 03-02-2011 at 04:23 PM..
# 18  
Old 03-03-2011
Hi Scrutinizer

All input records will not have the same number of work codes or pri codes.
One input record might have one input work code, then I would need 29 blank field for the output record.
The input number of work codes and pri codes will be different for each employee.
The number of work codes and pri code could also be different for the same employee.
What do I need to change to have it work this way?
THX again for your assisance.
# 19  
Old 03-03-2011
How about this:
Code:
awk -F\| 'function pr(){$0=s;NF+=30-m;$0=$0 t;NF+=30-n;print} 
          p!=$1 OFS $2{if(s)pr(); t=x; s=p=$1 OFS $2;m=n=0}
          $4""{s=s OFS $4;m++}
          $5""{t=t OFS $5;n++}
          END{pr()}' OFS=\| infile

# 20  
Old 03-03-2011
Scrutinizer,

The work codes are working there is 30 output fields, but I'm only getting 29 output fields for the pri codes.
What do I need to change?
THX
# 21  
Old 03-03-2011
I would suggest you experiment a little. Change the first 30 to 31 for example and see what it does...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

2. Programming

Gcc openmp programming problem

Dear Linux users, I'm a noob at openmp, gcc and c programming. I can run my own openmp code in terminal with no problem, eg. gcc -fopenmp program.c -o program. But now I'm trying to compile and run another person's code, it contains a makefile and multiple .c and .h files. I don't know how to... (2 Replies)
Discussion started by: pigeon151
2 Replies

3. Shell Programming and Scripting

AWK programming

Hi All, I read the AWK manual in the MAN page. But i didn't understand the below piece of code in the script TABLE=`echo "${FILE}" | awk -F"/" '{print $NF}' | cut -d"." -f1 | awk -F"_" '{print $NF}' 2>> ${LOGFILE}`; Please explain the above code. Thanks in advance ....... Regards,... (4 Replies)
Discussion started by: pdathu
4 Replies

4. Programming

Programming problem

Hi Everybody. I have an Ubuntu linux 10.04 os and want be able to use the website of intuit but it only runs on unix. Is there any way that I can put the needed drivers in this os since both linux/unix share some distinctive programs. If this is not possible how can I save the information that I... (1 Reply)
Discussion started by: mk631219
1 Replies

5. Shell Programming and Scripting

awk programming

Hi I have a multi -line file which is sorted by the 1-st colomn in the following format: 400 0000 0001 1000 1010 0111 0000 1000 0000 402 1101 0000 1100 1010 0111 1000 1000 0000 403 1001 0000 1100 1010 0111 0000 1000 0000 495 1000 0000 1100 ... (4 Replies)
Discussion started by: aoussenko
4 Replies

6. Shell Programming and Scripting

Problem with awk programming

i want to calculate power of 10 as follows: coef=2.0588 ra1=$(awk 'BEGIN{print 10^$coef}') it gives a result 1 when, if i calculate ra1=$(awk 'BEGIN{print 10^2.0588}') it gives a result 114.499 what should i do? (2 Replies)
Discussion started by: SANGUINE
2 Replies

7. UNIX for Advanced & Expert Users

RS232 programming problem

Hi all I encountered a strange phenomenon when reading / writing to RS232 serial device (on my machine /dev/ttyS0) I have simple 2 processes: 1) process which WRITE characters from /dev/ttyS0 For example write the characters... (2 Replies)
Discussion started by: dudi.forum
2 Replies

8. UNIX for Dummies Questions & Answers

awk (?) programming

Hello i need help with following problem: i need to update a file containing records in following format: student1 classa student2 classb student3 student4 classc i need to associate EACH student with a class in my output file ... so for students 3 and 4, i need to create a... (12 Replies)
Discussion started by: alrinno
12 Replies

9. Programming

C programming + problem with char arrays

Im trying to write some code atm which gets the complete pathname of a folder and strips off references to the parent folders. The end result should be just the name of the folder. Currently Im able to extract the folder name, however Im getting junk added onto the name as well which is making... (7 Replies)
Discussion started by: JamesGoh
7 Replies

10. Shell Programming and Scripting

awk programming

Hi folks, I would like to know the difference between shell programming and awk programming. Actually i have developed a few applications in both but i could not find a better difference other than the syntax differences. For example, the awk programming syntax is complicated. It has "{" and... (4 Replies)
Discussion started by: Nisha
4 Replies
Login or Register to Ask a Question