Sponsored Content
Top Forums Shell Programming and Scripting Awk formatting of a data file - nested for loops? Post 302211610 by catwoman on Friday 4th of July 2008 12:17:20 AM
Old 07-04-2008
Awk formatting of a data file - nested for loops?

Hello - is there any way in awk I can do...


4861 x(1) y(1) z(1)
4959 x(1) y(1) z(1)
5007 x(1) y(1) z(1)
4861 x(2) y(2) z(2)
4959 x(2) y(2) z(2)
5007 x(2) y(2) z(2)
4861 x(3) y(3) z(3)
4959 x(3) y(3) z(3)
5007 x(3) y(3) z(3)

to become...
4861 x(1) y(1) z(1) 4861 x(2) y(2) z(2) 4861 x(3) y(3) z(3)
4959 x(1) y(1) z(1) 4959 x(2) y(2) z(2) 4959 x(3) y(3) z(3)
5007 x(1) y(1) z(1) 5007 x(2) y(2) z(2) 5007 x(3) y(3) z(3)

In order to do this I've tried printing all lines associated with the 4861 measurement first, and then the same with 4959 and 5007, and was then going to merge them. For the first part, this is what I've got so far...

{for (k=1;k<4;k++) {
for (j=1+k;j<11;j=j+3) {
if (NR == j)
printf("%s\n", $0)
}
}}

..but this just prints out the lines in their original order. Is the reason why I can't do this because awk processes on a line by line basis rather than being able to dictate which lines I want to print out in a set order?

The only other thing I can think to do is merge all lines in this array, and then print the various fields I want to be on the same line.

Cheers Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grepping within nested for loops

Good morning - I have publication lists from 34 different faculty members. I need to end up with the numbers of publications in common across all 34 faculty. I need to grep person1 (last name) in list2, person1 in list3, person1 in list 4, etc., then person2 in list3, person 2 in list4, etc.,... (2 Replies)
Discussion started by: Peggy White
2 Replies

2. Shell Programming and Scripting

file reading in nested loops

I have to to read files simultaneously in two nested loops,but am getting error can anyone do the needful. useridFile=userIds.txt fname=kiran.txt exec<$useridFile while read line do echo "User IDs are..$line" USER_ID=$line REMOTE_DIR_LOCATION="/home/test/$USER_ID" SOURCE_DIR=$USER_ID... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

3. Shell Programming and Scripting

nested for loops

I need help getting over this bump on how nested for loops work in shell. Say i was comparing files in a directory in any other language my for loop would look like so for(int i=0;to then end; i++) for(int y = i+1; to the end; y++) I can't seem to understand how i can translate that... (5 Replies)
Discussion started by: taiL
5 Replies

4. Shell Programming and Scripting

formatting data file with awk or sed

Hi, I have a (quite large) data file which looks like: _____________ header part.. more header part.. x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 ... ... x59 x60 y1 y2 y3 y4... ... y100 ______________ where x1, x2,...,x60 and y1, y2,...y100 are numbers of 10 digits (so each line... (5 Replies)
Discussion started by: lego
5 Replies

5. Shell Programming and Scripting

KSH nested loops?

KSH isn't my strong suit but it's what my company has to offer. I've got a script with two nested loops, a FOR and UNTIL, and that works fine. When I add a CASE into the mix I end up getting "Unexpected 'done' at line xx" errors. Any suggestions on this? for divi in at ce ci cm co de di fl... (9 Replies)
Discussion started by: mrice
9 Replies

6. Shell Programming and Scripting

Nested for loops

Greetings All, The following script attempts to enumerate all users in all groups in the group file(GROUP) and echo the following information: GROUP ---> USER The script is as follows: IFS="," for GROUP in `ypcat -k group | cut -d" " -f1` do for USER in `ypcat -k group... (13 Replies)
Discussion started by: jacksolm
13 Replies

7. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

8. Shell Programming and Scripting

Two variables in output file name nested for loops

I am trying to use two nested for loops to process some files and then create a new file using both variables in the output file name. I have several files in this naming style: S1_L3_all_R1.fastq S1_L3_all_R2.fastq S1_L4_all_R1.fastq S1_L4_all_R2.fastq . . S1_L8_all_R1.fastq... (3 Replies)
Discussion started by: aminards
3 Replies

9. Shell Programming and Scripting

two while nested loops

for server in $(echo `cat /tmp/ScanHosts_${USERSNAME}.TXT`) do for portnumber in $(echo `cat /tmp/ScanPorts_${USERSNAME}.TXT`) do #echo ${server} ${portnumber} ... (3 Replies)
Discussion started by: SkySmart
3 Replies

10. UNIX for Beginners Questions & Answers

Nested Loops for text file

Hi A text file containing data something likeVehicle: BMW Class checkin_note: Tyre : Four path_id : 11 vault_file_size: -1 Vehicle: Toyota Class checkin_note: Tyre : Four path_id : 11 vault_file_size: -1 Vehicle: Chevrolet Class checkin_note: Tyre : Five path_id :... (7 Replies)
Discussion started by: vipinHasija
7 Replies
RTADVD(8)						    BSD System Manager's Manual 						 RTADVD(8)

NAME
rtadvd -- router advertisement daemon SYNOPSIS
rtadvd [-dDfRs] [-c configfile] [-C ctlsock] [-M ifname] [-p pidfile] [interface ...] DESCRIPTION
rtadvd sends router advertisement packets to the specified interfaces. If no interfaces are specified, rtadvd will still run, but will not advertise any routes until interfaces are added using rtadvctl(8). The program will daemonize itself on invocation. It will then send router advertisement packets periodically, as well as in response to router solicitation messages sent by end hosts. Router advertisements can be configured on a per-interface basis, as described in rtadvd.conf(5). If there is no configuration file entry for an interface, or if the configuration file does not exist altogether, rtadvd sets all the parame- ters to their default values. In particular, rtadvd reads all the interface routes from the routing table and advertises them as on-link prefixes. rtadvd also watches the routing table. If an interface direct route is added on an advertising interface and no static prefixes are speci- fied by the configuration file, rtadvd adds the corresponding prefix to its advertising list. Similarly, when an interface direct route is deleted, rtadvd will start advertising the prefixes with zero valid and preferred lifetimes to help the receiving hosts switch to a new prefix when renumbering. Note, however, that the zero valid lifetime cannot invalidate the autocon- figured addresses at a receiving host immediately. According to the specification, the host will retain the address for a certain period, which will typically be two hours. The zero lifetimes rather intend to make the address deprecated, indicating that a new non-deprecated address should be used as the source address of a new connection. This behavior will last for two hours. Then rtadvd will completely remove the prefix from the advertising list, and succeeding advertisements will not contain the prefix information. Moreover, if the status of an advertising interface changes, rtadvd will start or stop sending router advertisements according to the latest status. The -s option may be used to disable this behavior; rtadvd will not watch the routing table and the whole functionality described above will be suppressed. Basically, hosts MUST NOT send Router Advertisement messages at any time (RFC 4861, Section 6.2.3). However, it would sometimes be useful to allow hosts to advertise some parameters such as prefix information and link MTU. Thus, rtadvd can be invoked if router lifetime is explic- itly set zero on every advertising interface. The command line options are: -c Specify an alternate location, configfile, for the configuration file. By default, /etc/rtadvd.conf is used. -C Specify an alternate location for the control socket used by rtadvctl(8). The default is /var/run/rtadvd.sock. -d Print debugging information. -D Even more debugging information is printed. -f Foreground mode (useful when debugging). Log messages will be dumped to stderr when this option is specified. -M Specify an interface to join the all-routers site-local multicast group. By default, rtadvd tries to join the first advertising interface appearing on the command line. This option has meaning only with the -R option, which enables routing renumbering protocol support. -p Specify an alternative file in which to store the process ID. The default is /var/run/rtadvd.pid. -R Accept router renumbering requests. If you enable it, certain IPsec setup is suggested for security reasons. This option is cur- rently disabled, and is ignored by rtadvd with a warning message. -s Do not add or delete prefixes dynamically. Only statically configured prefixes, if any, will be advertised. Use SIGHUP to reload the configuration file /etc/rtadvd.conf. If an invalid parameter is found in the configuration file upon the reload, the entry will be ignored and the old configuration will be used. When parameters in an existing entry are updated, rtadvd will send Router Advertisement messages with the old configuration but zero router lifetime to the interface first, and then start to send a new message. Use SIGTERM to kill rtadvd gracefully. In this case, rtadvd will transmit router advertisement with router lifetime 0 to all the interfaces (in accordance with RFC 4861 6.2.5). FILES
/etc/rtadvd.conf The default configuration file. /var/run/rtadvd.pid The default process ID file. EXIT STATUS
The rtadvd utility exits 0 on success, and >0 if an error occurs. SEE ALSO
rtadvd.conf(5), rtadvctl(8), rtsol(8) Thomas Narten, Erik Nordmark, W. A. Simpson, and Hesham Soliman, Neighbor Discovery for IP version 6 (IPv6), RFC 4861. Thomas Narten, Erik Nordmark, and W. A. Simpson, Neighbor Discovery for IP version 6 (IPv6), RFC 2461 (obsoleted by RFC 4861). Richard Draves, Default Router Preferences and More-Specific Routes, draft-ietf-ipngwg-router-selection-xx.txt. J. Jeong, S. Park, L. Beloeil, and S. Madanapalli, IPv6 Router Advertisement Options for DNS Configuration, RFC 6106. HISTORY
The rtadvd command first appeared in the WIDE Hydrangea IPv6 protocol stack kit. BUGS
There used to be some text that recommended users not to let rtadvd advertise Router Advertisement messages on an upstream link to avoid undesirable icmp6(4) redirect messages. However, based on the later discussion in the IETF ipng working group, all routers should rather advertise the messages regardless of the network topology, in order to ensure reachability. BSD
February 25, 2013 BSD
All times are GMT -4. The time now is 07:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy