The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
comparing values Aditya.Gurgaon Shell Programming and Scripting 1 03-08-2009 11:25 PM
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 07:05 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
replace a column values with the first value in column sumeet UNIX for Advanced & Expert Users 3 02-06-2007 01:13 PM
comparing two float values kavitha Shell Programming and Scripting 2 04-03-2004 02:32 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-08-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0