Sponsored Content
Full Discussion: Comparing values in column 1
Top Forums Shell Programming and Scripting Comparing values in column 1 Post 302314286 by cgkmal on Friday 8th of May 2009 02:23:02 AM
Old 05-08-2009
Comparing values in column 1

Hi to all,

I have the following text within inputfile

Code:
data1,value1,value2
data1,value3,value2
data1,value5,value6

data2,value1,value2
data2,value3,value4

data3,value1,value2
data3,value3,value4

data4,value1,value2
data4,value3,value4
data4,value5,value6

I would like to associate in the same line all values taking as common value $1. I mean, compare the values in column 1 for consecutive lines, and
if $1 of line_n is equal to $1 of line_n+1 put the data as follow:

Code:
data1,value1,value3,value5,value2,value4,value6
data2,value1,value3,value2,value4
data3,value1,value3,value2,value4
data4,value1,value3,value5,value2,value4,value6

I think this could be done using FNR and/or NR variables, but I donīt know
how to use them for this task.

I was trying the next line, but fails because some syntax error:

awk '{arr[i]==$1++}; {if{arr[i]==arr[i+1]}} {print $0, getline; print $0}' inputfile

and something like NR=FNR, but I donīt know how.

Please any help will be very appreciated.

Best regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comparing values

i have two file and i am comparing both.. in cmp1 ,the content is : the nu of file is : <some integer value> in cmp2 ,the content is : the nu of file is : so want a script which will take value (2) when cmp1 is compared with cmp2.. i mean cmp cmp1 cmp2 the the output will be he nu of... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

2. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

3. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

4. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

5. Shell Programming and Scripting

Cat Values from Several files if it meets criteria for column values

I have results from some statistical analyses. The format of the results are as given below: I want to select lines that have a p-value (last column) less than 0.05 from all the results files (*.results) and cat to a new results file. It would be very nice if a new column is added that tells... (2 Replies)
Discussion started by: genehunter
2 Replies

6. UNIX for Dummies Questions & Answers

shift values in one column as header for values in another column

Hi Gurus, I have a tab separated text file with two columns. I would like to make the first column values as headings for the second column values. Ex. >value1 subjects >value2 priorities >value3 requirements ...etc and I want to have a file >value1 subjects >value2 priorities... (4 Replies)
Discussion started by: Unilearn
4 Replies

7. UNIX for Dummies Questions & Answers

Comparing two text files by a column and printing values that do not match

I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that? File 1: 100 rs3794811 0.01 0.3434 100 rs8066551 0.01... (8 Replies)
Discussion started by: evelibertine
8 Replies

8. Shell Programming and Scripting

Converting odd values to even values(or vice-versa) located in a column

Hello All, I have a below data in a .csv file where all rows where col1 is A, col2 is odd numbers, similarly even numbers for all rows where col1 is B. Note that my data has some other columns(not shown here) too (around 100) after col2. Tool,Data A,1 A,3 A,5 .... so on B,2 B,4 .... ... (4 Replies)
Discussion started by: ks_reddy
4 Replies

9. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

10. Shell Programming and Scripting

Comparing same column from two files, printing whole row with matching values

First I'd like to apologize if I opened a thread which is already open somewhere. I did a bit of searching but could quite find what I was looking for, so I will try to explaing what I need. I'm writing a script on our server, got to a point where I have two files with results. Example: File1... (6 Replies)
Discussion started by: mitabrev83
6 Replies
Dumpvalue(3pm)						 Perl Programmers Reference Guide					    Dumpvalue(3pm)

NAME
Dumpvalue - provides screen dump of Perl data. SYNOPSIS
use Dumpvalue; my $dumper = Dumpvalue->new; $dumper->set(globPrint => 1); $dumper->dumpValue(*::); $dumper->dumpvars('main'); my $dump = $dumper->stringify($some_value); DESCRIPTION
Creation A new dumper is created by a call $d = Dumpvalue->new(option1 => value1, option2 => value2) Recognized options: "arrayDepth", "hashDepth" Print only first N elements of arrays and hashes. If false, prints all the elements. "compactDump", "veryCompact" Change style of array and hash dump. If true, short array may be printed on one line. "globPrint" Whether to print contents of globs. "dumpDBFiles" Dump arrays holding contents of debugged files. "dumpPackages" Dump symbol tables of packages. "dumpReused" Dump contents of "reused" addresses. "tick", "quoteHighBit", "printUndef" Change style of string dump. Default value of "tick" is "auto", one can enable either double-quotish dump, or single-quotish by setting it to """ or "'". By default, characters with high bit set are printed as is. If "quoteHighBit" is set, they will be quoted. "usageOnly" rudimentary per-package memory usage dump. If set, "dumpvars" calculates total size of strings in variables in the package. unctrl Changes the style of printout of strings. Possible values are "unctrl" and "quote". subdump Whether to try to find the subroutine name given the reference. bareStringify Whether to write the non-overloaded form of the stringify-overloaded objects. quoteHighBit Whether to print chars with high bit set in binary or "as is". stopDbSignal Whether to abort printing if debugger signal flag is raised. Later in the life of the object the methods may be queries with get() method and set() method (which accept multiple arguments). Methods dumpValue $dumper->dumpValue($value); $dumper->dumpValue([$value1, $value2]); Prints a dump to the currently selected filehandle. dumpValues $dumper->dumpValues($value1, $value2); Same as "$dumper->dumpValue([$value1, $value2]);". stringify my $dump = $dumper->stringify($value [,$noticks] ); Returns the dump of a single scalar without printing. If the second argument is true, the return value does not contain enclosing ticks. Does not handle data structures. dumpvars $dumper->dumpvars('my_package'); $dumper->dumpvars('my_package', 'foo', '~bar$', '!......'); The optional arguments are considered as literal strings unless they start with "~" or "!", in which case they are interpreted as regular expressions (possibly negated). The second example prints entries with names "foo", and also entries with names which ends on "bar", or are shorter than 5 chars. set_quote $d->set_quote('"'); Sets "tick" and "unctrl" options to suitable values for printout with the given quote char. Possible values are "auto", "'" and """. set_unctrl $d->set_unctrl('unctrl'); Sets "unctrl" option with checking for an invalid argument. Possible values are "unctrl" and "quote". compactDump $d->compactDump(1); Sets "compactDump" option. If the value is 1, sets to a reasonable big number. veryCompact $d->veryCompact(1); Sets "compactDump" and "veryCompact" options simultaneously. set $d->set(option1 => value1, option2 => value2); get @values = $d->get('option1', 'option2'); perl v5.18.2 2013-11-04 Dumpvalue(3pm)
All times are GMT -4. The time now is 08:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy