Sponsored Content
Top Forums Shell Programming and Scripting How to replicate data using Uniq or awk Post 302225969 by ahjiefreak on Monday 18th of August 2008 12:07:12 AM
Old 08-18-2008
Hi,

How do you decide which "orange" line to duplicate? Is it always the first one?
> It is always taking from the first one.
E.g if the data have

1,2,3,4,5,6,apple
1,1,0,4,2,3,apple
1,3,3,3,3,4,apple
1,1,0,4,2,3,apple
1,3,3,3,3,4,apple
1,1,1,1,1,1,orange
1,2,3,1,1,1,orange

So, it will have repeated of orange dataset from the first occurrence of orange until it fulfill the similar number of items of orange as apple:-
1,2,3,4,5,6,apple
1,1,0,4,2,3,apple
1,3,3,3,3,4,apple
1,1,0,4,2,3,apple
1,3,3,3,3,4,apple
1,1,1,1,1,1,orange
1,2,3,1,1,1,orange
1,1,1,1,1,1,orange
1,2,3,1,1,1,orange
1,1,1,1,1,1,orange

Will it always be 3 and 2, or do those quantities vary? Is there other data in the file as well, or is that everything in the file?
>The number can be 0,1,...100,.all the integers but no negative numbers.
The real data in the file contains more than 6 numbers with ",". There can be up to hundreds of numbers with ",". But i think it would be similar case handle using this small data example?



Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using uniq and awk??

I have a file that is populated: hits/books.hits:143.217.64.204 Thu Sep 21 22:24:57 GMT 2006 hits/books.hits:62.145.39.14 Fri Sep 22 00:38:32 GMT 2006 hits/books.hits:81.140.86.170 Fri Sep 22 08:45:26 GMT 2006 hits/books.hits:81.140.86.170 Fri Sep 22 09:13:57 GMT... (13 Replies)
Discussion started by: amatuer_lee_3
13 Replies

2. Shell Programming and Scripting

Help needed with Sort and uniq data

Hi All, After Sorting directories and files i have got following output as below, now i only want the strings common in them, so the actual output should be as below in the bottom. How do i do that? Thanks -adsi File to be modified:- Common Components for ----> AA... (4 Replies)
Discussion started by: asirohi
4 Replies

3. Shell Programming and Scripting

Help with uniq or awk??

Hi, my dilemna is this: example i got a file of fruit.txt which contains: Apple 6 Apple_new 7 old_orange 9 orange 10 Is there any way for me to have an output of Apple 13 Orange 19 using shell script: (6 Replies)
Discussion started by: shinoman28
6 Replies

4. Shell Programming and Scripting

Modify log files to get uniq data

Hello, I have a log file that has following output as below. LAP.sun5 CC LAP.sun5 CQ perl.sun5 CC perl.sun5 CQ TSLogger.sun5 CC TSLogger.sun5 CQ TSLogger.sun5 KR WAS.sun5 CC WAS.sun5 MT WAS.sun5 CQ I want to output to be in the way below, i tried using awk but could not do it. ... (12 Replies)
Discussion started by: asirohi
12 Replies

5. UNIX for Dummies Questions & Answers

Finding and Extracting uniq data in multiple files

Hi, I have several files that look like this: File1.txt Data1 Data2 Data20 File2.txt Data1 Data5 Data10 File3.txt Data1 Data2 Data17 File4.txt (6 Replies)
Discussion started by: Fahmida
6 Replies

6. Shell Programming and Scripting

replicate lines - awk

Is it possible to replicate the lines based on 4th column of the input like the below ? input ar1 10 100 -1 ar1 20 200 -2 arX 34 140 +1 arY 7 1 +4 output ar1 10 100 - ar1 20 200 - ar1 20 200 - arX 34 140 + arY ... (1 Reply)
Discussion started by: quincyjones
1 Replies

7. Shell Programming and Scripting

Find the replicate record using awk

We usually use the following awk code to delete of find out the replicate record. awk -F, '{a++} END {for (i in a) if (a>=2) print i a}' file My question is how can I print the whole record. The following code doesn't work. awk -F, '{a++} END {for (i in a) if (a>=2) print $0}' file ... (8 Replies)
Discussion started by: xshang
8 Replies

8. Shell Programming and Scripting

Filtering data using uniq and sed

Hello, Does anyone know an easy way to filter this type of file? I want to get everything that has score (column 2) 100.00 and get rid of duplicates (for example gi|332198263|gb|EGK18963.1| below), so I guess uniq can be used for this? gi|3379182634|gb|EGK18561.1| 100.00... (6 Replies)
Discussion started by: narachaid
6 Replies

9. Shell Programming and Scripting

Combine data from two files base on uniq data

File 1 ID Name Po1 Po2 DD134 DD134_4A_1 NN-1 L_0_1 DD134 DD134_4B_1 NN-2 L_1_1 DD134 DD134_4C_1 NN-3 L_2_1 DD142 DD142_4A_1 NN-1 L_0_1 DD142 DD142_4B_1 NN-2 L_1_1 DD142 DD142_4C_1 NN-3 L_2_1 DD142 DD142_3A_1 NN-41 L_3_1 DD142 DD142_3A_1 NN-42 L_3_2 File 2 ( Combination of... (1 Reply)
Discussion started by: pareshkp
1 Replies

10. Shell Programming and Scripting

Need help in awk: running a loop with one column and segregate data 4 each uniq value in that field

Hi All, I have a file like this(having 2 column). Column 1: like a,b,c.... Column 2: having numbers. I want to segregate those numbers based on column 1. Example: file. a 5 b 9 b 620 a 710 b 230 a 330 b 1910 (4 Replies)
Discussion started by: Raza Ali
4 Replies
OCI_DEFINE_BY_NAME(3)													     OCI_DEFINE_BY_NAME(3)

oci_define_by_name - Associates a PHP variable with a column for query fetches

SYNOPSIS
bool oci_define_by_name (resource $statement, string $column_name, mixed &$variable, [int $type = SQLT_CHR]) DESCRIPTION
Associates a PHP variable with a column for query fetches using oci_fetch(3). The oci_define_by_name(3) call must occur before executing oci_execute(3). PARAMETERS
o $statement -A valid OCI8 statement identifier created by oci_parse(3) and executed by oci_execute(3), or a REF CURSOR statement identifier. o $column_name - The column name used in the query. Use uppercase for Oracle's default, non-case sensitive column names. Use the exact column name case for case-sensitive column names. o $variable - The PHP variable that will contain the returned column value. o $type - The data type to be returned. Generally not needed. Note that Oracle-style data conversions are not performed. For example, SQLT_INT will be ignored and the returned data type will still be SQLT_CHR. You can optionally use oci_new_descriptor(3) to allo- cate LOB/ROWID/BFILE descriptors. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 oci_define_by_name(3) example <?php $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $sql = 'SELECT location_id, city FROM locations WHERE location_id < 1200'; $stid = oci_parse($conn, $sql); // The defines MUST be done before executing oci_define_by_name($stid, 'LOCATION_ID', $locid); oci_define_by_name($stid, 'CITY', $city); oci_execute($stid); // Each fetch populates the previously defined variables with the next row's data while (oci_fetch($stid)) { echo "Location id $locid is $city<br> "; } // Displays: // Location id 1000 is Roma // Location id 1100 is Venice oci_free_statement($stid); oci_close($conn); ?> Example #2 oci_define_by_name(3) with case sensitive column names <?php /* Before running, create the table with a case sensitive column name: CREATE TABLE mytab (id NUMBER, "MyDescription" VARCHAR2(30)); INSERT INTO mytab (id, "MyDescription") values (1, 'Iced Coffee'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT * FROM mytab'); // Use uppercase for non case-sensitive column names oci_define_by_name($stid, 'ID', $id); // Use the exact case for case-sensitive column names oci_define_by_name($stid, 'MyDescription', $mydesc); oci_execute($stid); while (oci_fetch($stid)) { echo "id $id is $mydesc<br> "; } // Displays: // id 1 is Iced Coffee oci_free_statement($stid); oci_close($conn); ?> Example #3 oci_define_by_name(3) with LOB columns <?php /* Before running, create the table: CREATE TABLE mytab (id NUMBER, fruit CLOB); INSERT INTO mytab (id, fruit) values (1, 'apple'); INSERT INTO mytab (id, fruit) values (2, 'orange'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT * FROM mytab'); // The defines MUST be done before executing oci_define_by_name($stid, 'ID', $id); oci_define_by_name($stid, 'FRUIT', $fruit); // $fruit will become a LOB descriptor oci_execute($stid); while (oci_fetch($stid)) { echo $id . " is " . $fruit->load(100) . "<br> "; } // Displays: // 1 is apple // 2 is orange $fruit->free(); oci_free_statement($stid); oci_close($conn); ?> Example #4 oci_define_by_name(3) with an explicit type <?php /* Before running, create the table: CREATE TABLE mytab (id NUMBER, fruit CLOB); INSERT INTO mytab (id, fruit) values (1, 'apple'); INSERT INTO mytab (id, fruit) values (2, 'orange'); COMMIT; */ $conn = oci_connect('hr', 'welcome', 'localhost/XE'); if (!$conn) { $e = oci_error(); trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); } $stid = oci_parse($conn, 'SELECT * FROM mytab'); // The defines MUST be done before executing oci_define_by_name($stid, 'ID', $id); $fruit = oci_new_descriptor($conn, OCI_D_LOB); oci_define_by_name($stid, 'FRUIT', $fruit, OCI_D_CLOB); oci_execute($stid); while (oci_fetch($stid)) { echo $id . " is " . $fruit->load(100) . "<br> "; } // Displays: // 1 is apple // 2 is orange $fruit->free(); oci_free_statement($stid); oci_close($conn); ?> SEE ALSO
oci_fetch(3), oci_new_descriptor(3). PHP Documentation Group OCI_DEFINE_BY_NAME(3)
All times are GMT -4. The time now is 09:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy