Sponsored Content
Top Forums Shell Programming and Scripting Sort a the file & refine data column & row format Post 302544753 by Chubler_XL on Friday 5th of August 2011 12:06:08 AM
Old 08-05-2011
How about this awk script:

Code:
awk '
NF==0 {
  if(keystr) print substr(keystr,2);
  print substr(vals,2);
  vals=keystr=""
  next
}
{
    gsub(/[\":]/," ",$0);
    key=$1;
    for(i=2;i<NF;i++) key=key$i;
    if(!(key in have)) {
        keystr=keystr" "key
        have[key]
    }
    vals=vals" "$i }
END { print substr(vals,2) }' infile


Last edited by Chubler_XL; 08-05-2011 at 01:11 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

2. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

3. Shell Programming and Scripting

sort the org_no & member_type column ascending

I have a FILE1.DAT with the following information 21111111110001343 000001004OLF-AA029100020091112 21111111110000060 000001004ODL-CH001000020091112 24444444440001416 000001045OLF-AA011800020091112 23333333330001695 000001039OLF-AA030600020091112 23333333330000111... (5 Replies)
Discussion started by: new2ksh
5 Replies

4. Shell Programming and Scripting

replace & with &amp; xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

5. UNIX for Dummies Questions & Answers

How to remove duplicated based on longest row & largest value in a column

Hii i have a file with data as shown below. Here i need to remove duplicates of the rows in such a way that it just checks for 2,3,4,5 column for duplicates.When deleting duplicates,retain largest row i.e with many columns with values should be selected.Then it must remove duplicates such that by... (11 Replies)
Discussion started by: reva
11 Replies

6. Shell Programming and Scripting

awk/sed to search & replace data in first column

Hi All, I need help in manipulating the data in first column in a file. The sample data looks like below, Mon Jul 18 00:32:52 EDT 2011,NULL,UAT Jul 19 2011,NULL,UAT 1] All field in the file are separated by "," 2] File is having weekly data extracted from database 3] For eg.... (8 Replies)
Discussion started by: gr8_usk
8 Replies

7. Shell Programming and Scripting

Sort data from column to row

Hi, I need somebody's help with sorting data with awk. I've got a file: 10 aaa 4584 12 bbb 6138 20 ccc 4417 21 ddd 7796 10 eee 7484 12 fff ... (5 Replies)
Discussion started by: killerbee
5 Replies

8. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

9. Shell Programming and Scripting

File Move & Sort by Name - Kick out Bad File Names & More

I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following: Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Discussion started by: Nvizn
8 Replies

10. UNIX for Beginners Questions & Answers

Shell command to transpose Row & Column

Hi all, need a help with getting a one line command to do the following. i have an input file with rows of data containing credits for each office, the output should be one row for each office with all the credits in rows for that office, if its not there then it should say N/A. the credits are... (10 Replies)
Discussion started by: tech_frk
10 Replies
RAND(3P)						     POSIX Programmer's Manual							  RAND(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
rand, rand_r, srand - pseudo-random number generator SYNOPSIS
#include <stdlib.h> int rand(void); int rand_r(unsigned *seed); void srand(unsigned seed); DESCRIPTION
The rand() function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}] with a period of at least 2**32. The rand() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe. The rand_r() function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}]. (The value of the {RAND_MAX} macro shall be at least 32767.) If rand_r() is called with the same initial value for the object pointed to by seed and that object is not modified between successive returns and calls to rand_r(), the same sequence shall be generated. The srand() function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand() is called before any calls to srand() are made, the same sequence shall be generated as when srand() is first called with a seed value of 1. The implementation shall behave as if no function defined in this volume of IEEE Std 1003.1-2001 calls rand() or srand(). RETURN VALUE
The rand() function shall return the next pseudo-random number in the sequence. The rand_r() function shall return a pseudo-random integer. The srand() function shall not return a value. ERRORS
No errors are defined. The following sections are informative. EXAMPLES
Generating a Pseudo-Random Number Sequence The following example demonstrates how to generate a sequence of pseudo-random numbers. #include <stdio.h> #include <stdlib.h> ... long count, i; char *keystr; int elementlen, len; char c; ... /* Initial random number generator. */ srand(1); /* Create keys using only lowercase characters */ len = 0; for (i=0; i<count; i++) { while (len < elementlen) { c = (char) (rand() % 128); if (islower(c)) keystr[len++] = c; } keystr[len] = ''; printf("%s Element%0*ld ", keystr, elementlen, i); len = 0; } Generating the Same Sequence on Different Machines The following code defines a pair of functions that could be incorporated into applications wishing to ensure that the same sequence of numbers is generated across different machines. static unsigned long next = 1; int myrand(void) /* RAND_MAX assumed to be 32767. */ { next = next * 1103515245 + 12345; return((unsigned)(next/65536) % 32768); } void mysrand(unsigned seed) { next = seed; } APPLICATION USAGE
The drand48() function provides a much more elaborate random number generator. The limitations on the amount of state that can be carried between one function call and another mean the rand_r() function can never be implemented in a way which satisfies all of the requirements on a pseudo-random number generator. Therefore this function should be avoided whenever non-trivial requirements (including safety) have to be fulfilled. RATIONALE
The ISO C standard rand() and srand() functions allow per-process pseudo-random streams shared by all threads. Those two functions need not change, but there has to be mutual-exclusion that prevents interference between two threads concurrently accessing the random number gener- ator. With regard to rand(), there are two different behaviors that may be wanted in a multi-threaded program: 1. A single per-process sequence of pseudo-random numbers that is shared by all threads that call rand() 2. A different sequence of pseudo-random numbers for each thread that calls rand() This is provided by the modified thread-safe function based on whether the seed value is global to the entire process or local to each thread. This does not address the known deficiencies of the rand() function implementations, which have been approached by maintaining more state. In effect, this specifies new thread-safe forms of a deficient function. FUTURE DIRECTIONS
None. SEE ALSO
drand48(), the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 RAND(3P)
All times are GMT -4. The time now is 10:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy