Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Compare column data in all the rows Post 302861583 by NareshN on Wednesday 9th of October 2013 08:50:49 AM
Old 10-09-2013
[Solved] Compare column data in all the rows

Hi..

In the below sorted input file.. I am comparing the first 3 columns of data one by one row and it is a pipeline delimitter file..
Code:
AA|BB|CC|line1
AA|BB|CC|ine4
AA|BB|CC|line2
BB|CC|DD|line3
BB|CC|DD|line5

If first 3 columns of data matches with any record in the file the expected
output will be

Code:
AA|BB|CC|line1,line4
AA|BB|CC|line2
BB|CC|DD|line3,line5

I know it will be possible through awk command.. please help on this

---------- Post updated at 06:20 PM ---------- Previous update was at 04:46 PM ----------

Hi..


I have just tried and it got worked the below script.. But i need in one line of command by using "awk"..

Code:
rm opfile
inputfile=ip-file
cut -d'|' -f1-3 $inputfile | sort | uniq  > temp
t=1
NumOfRec=`wc -l < temp`
while [ $t -le $NumOfRec ]
do
 rec=`head -$t temp | tail -1`
 grep "$rec" $inputfile | awk -F'|' '{print $4}' | tr -s  '\n' ',' | read lastcol
 
 echo "$rec|$lastcol" >> opfile
 
 t=`expr $t \+ 1`
done


Last edited by vbe; 10-09-2013 at 10:17 AM.. Reason: corrected faulty code to icode tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find different column numbers among rows in data

I want to find the different column numbers among rows in a file. For example: A001 a b c d e ... N A002 a b c d e ... N A003 a b c d e ... N+1 A004 a b c d e ... N A005 a b c d e ... N+2 : : For most of the lines I will have N columns (say 1000 rows) in each line except the line 3... (5 Replies)
Discussion started by: AMBER
5 Replies

2. Shell Programming and Scripting

column data to rows every n line

Hi every one, I am trying to organise an input text file like: input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 into an output as following: output file 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 (5 Replies)
Discussion started by: nxp
5 Replies

3. UNIX for Dummies Questions & Answers

[SOLVED] splitting a single column(with spaces) into multiple rows

Hi All, My requisite is to split a single column of phonemes seperated by spaces into multiple rows. my input file is: a dh u th a qn ch A v U r k my o/p should be like: adhu a dh u (3 Replies)
Discussion started by: girlofgenuine
3 Replies

4. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

Transpose Column of Data to Rows

I can no longer find my commands, but I use to be able to transpose data with common fields from a single column to rows using a command line. My data is separated as follows: NAME=BOB ADDRESS=COLORADO PET=CAT NAME=SUSAN ADDRESS=TEXAS PET=BIRD NAME=TOM ADDRESS=UTAH PET=DOG I would... (7 Replies)
Discussion started by: docdave78
7 Replies

7. Shell Programming and Scripting

Data rearranging from rows to column

Hello Everyone, I have a input file looks like -0.005-0.004-0.003-0.002-0.00100.0010.0020.0030.0040.005My desired output should look like -0.005 -0.004 -0.003 -0.002 -0.001 0 0.001 0.002 0.003 0.004 0.005I had some success in getting the desired output. But i face a problem when i... (15 Replies)
Discussion started by: dinesh.n
15 Replies

8. Shell Programming and Scripting

How to separate rows of data into another column?

I have data such as below where the value in second field is the same as that in the row after. 123456,22222,John,0,xyz 234567,22222,John1,1,cde 43212,3333,Jean,3,pip 84324,3333,Abel,2,cat I'd like to rearrange the output like below to put such records beside each other and separated with... (5 Replies)
Discussion started by: james2009
5 Replies

9. UNIX for Dummies Questions & Answers

Compare data - Match first column and compare second

Hi guys, looking for some help with a way to compare data in two files but with some conditions. example, File 1 consists of site1,10.1.1.1 site2,20.2.2.2 site3,30.3.3.3 File 2 contains site1,l0.1.1.1 site2,50.1.1.1 site3,30.3.3.3 site4,40.1.1.1 I want to be able to match the... (1 Reply)
Discussion started by: mutley2202
1 Replies

10. UNIX for Beginners Questions & Answers

Compare values in multiple rows in one column using awk

I would like to compare values in column 8, and grep the ones where the different is > 1, columns 1 and 2 are the key for array. Every 4 rows the records values in columns 1 and 2 changed. Then, the comparison in the column 8 need to be done for the 4 rows everytime columns 1 and 2 changed ... (4 Replies)
Discussion started by: jiam912
4 Replies
MIXER(8)						    BSD System Manager's Manual 						  MIXER(8)

NAME
mixer -- set/display soundcard mixer values SYNOPSIS
mixer [-f device] [-s | -S] [dev [[+|-]lvol[:[+|-]rvol]]] ... mixer [-f device] [-s | -S] recsrc ... mixer [-f device] [-s | -S] {^|+|-|=}rec rdev ... DESCRIPTION
The mixer utility is used to set and display soundcard mixer device levels. It may also be used to start and stop recording from the sound- card. The list of mixer devices that may be modified are: vol, bass, treble, synth, pcm, speaker, line, mic, cd, mix, pcm2, rec, igain, ogain, line1, line2, line3, dig1, dig2, dig3, phin, phout, video, radio, and monitor. Not all mixer devices are available. Without any arguments, mixer displays the current settings for all supported devices, followed by information about the current recording input devices. If the dev argument is specified, mixer displays only the value for that dev. To modify the mixer value dev, the optional left and right channel settings of lvol[:rvol] may be specified. The lvol and rvol arguments may be from 0 - 100. Omitting dev and including only the channel settings will change the main volume level. If the left or right channel settings are prefixed with + or -, the value following will be used as a relative adjustment, modifying the cur- rent settings by the amount specified. If the -s flag is used, the current mixer values will be displayed in a format suitable for use as the command-line arguments to a future invocation of mixer (as above). The -S flag provides the above output without mixing field separators. To change the recording device you use one of: ^rec toggles rdev of possible recording devices +rec adds rdev to possible recording devices -rec removes rdev from possible recording devices =rec sets the recording device to rdev The above commands work on an internal mask. After all the options have been parsed, it will set then read the mask from the sound card. This will let you see EXACTLY what the soundcard is using for the recording device(s). The option recsrc will display the current recording devices. The option -f device will open device as the mixer device. FILES
/dev/mixer the default mixer device SEE ALSO
cdcontrol(1), sound(4) HISTORY
The mixer utility first appeared in FreeBSD 2.0.5. AUTHORS
Original source by Craig Metz <cmetz@thor.tjhsst.edu> and Hannu Savolainen. Mostly rewritten by John-Mark Gurney <jmg@FreeBSD.org>. This manual page was written by Mike Pritchard <mpp@FreeBSD.org>. BSD
June 2, 2014 BSD
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy