![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need Help with awk and arrays | fusionX | Shell Programming and Scripting | 7 | 02-11-2008 06:41 PM |
| awk arrays | imonthejazz | Shell Programming and Scripting | 1 | 09-21-2007 09:29 AM |
| arrays in awk??? | craigsky | Shell Programming and Scripting | 3 | 08-27-2007 09:13 PM |
| KSH and arrays | whited05 | Shell Programming and Scripting | 1 | 06-24-2005 12:07 PM |
| Two or more arrays in Awk | nitin | UNIX for Advanced & Expert Users | 1 | 12-10-2001 09:37 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Arrays in awk
Hi, I've written the following code to manipulate the first 40 lines of a data file into my desired order:
#!/bin/awk -f { if (NR<=(4)){ a[NR]=a[NR]$0" "} else { if ((NR >= (5)) && (NR <= (13))) { b[NR%3]=b[NR%3]$0" " } else {if ((NR >= (14)) && (NR <= (25))){ c[NR%3]=c[NR%3]$0" "} else{if ((NR>=(26)) && (NR<=(40))){ d[NR%3]=d[NR%3]$0" "} }}}} END {{for (i in a) {print a[i]} } {for (i in b) { print b[i]} } {for (i in c) {print c[i]} } {for (i in d) {print d[i]} }} However, I want to apply this sorting to every set of 40 lines in the data file, where the data files are 10000+ lines. I tried enclosing the entire code in a for loop but this didn't work as the a, b, c and d arrays in each block of 40 lines would have to change as well. Can arrays be given numerical names so they could be incremented with each execution of the for loop? Many thanks ![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|