Multiple lines consolidate


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple lines consolidate
# 1  
Old 03-31-2012
Multiple lines consolidate

This post is start for me ... I stumped at something that I not sure as to how start on ... I tried so of your script that i honestly lost mind looking and looking here ... please help
Code:
COL1       COl2       COL3
12222     AUH         FLUEH
12222     SSC          OPERA
12222     SSC          OPERA

(SSC shows 2 occurences & AUH1 Occurences)
Code:
12223     SSC          OPERA
12223     AUH          FLUEH
12223     SSC          OPERA
12223     SSC          OPERA

(SSC shows 3 occurences & AUH1 Occurences)

RESULT -
Code:
12222     SSC-2 AUH-1 OPERA-2 FLUEH-1
12223     SSC-3 AUH-1 OPERA-3 FLUEH-1

How should I do this?

-- All i do, is

Code:
awk -F"\t" '{a[$2" " $4]++;a[$2" " $4]+=$NF} END {for (i in a){print i,a[i]}}' WINTER_SHOPPE

but that is not giving answer as it accounts only 2 column result.

Can anyone of you help please ?

Moderator's Comments:
Mod Comment welcome to the forum, please use [code] tags also for data samples...

Last edited by Scrutinizer; 03-31-2012 at 06:20 AM..
# 2  
Old 03-31-2012
Can only these four words appear and do you want to list 0 or more occurrences of these words in COL2 and COL3 for every distinct value in COL1, or do you just want to list the number of occurrences for anything that appears in COL2 and COL3 in no particular order?
# 3  
Old 03-31-2012
awk

Hi,
welcome to the unix and linux forum:-)
Code:
awk 'BEGIN{ORS="";}{a[$1"^"$2]  ;a[$1"^"$3]  ;}END{asort(a);for(i in a){split(i,b,"^");if(b[1] ~ l){print b[2]"-"a[i];}else{print "\n"b[1];}l=b[1];}}' file

It works when it is sorted. Please make sure you have asort.
Cheers,
Ranga:-)
# 4  
Old 03-31-2012
Sorry,,, I saw error

awk: calling undefined function asort
...

Scrutinizer,

si, only AUH, FLUEH, SSC, OPERA, and SSC FLORE appear in data set.

Thank you.

Sebastian.
# 5  
Old 03-31-2012
SSC FLORE is two words, no?
# 6  
Old 03-31-2012
awk

Hi,
i think you dont have asort funtion,
Try this one,

Code:
awk 'BEGIN{ORS="";f[1]="AUH";f[2]="FLUEH";f[3]="SSC";f[4]="OPERA";f[5]="FLORE";}{a[$1"^"$2]  ;a[$1"^"$3]  ;c[$1]=1;}END{for(i in c){print i;for(j=1;j<=length(f);j  ){fld=f[j];if(a[i"^"fld]){print fld"-"a[i"^"fld];}}print "\n";}}' file

Cheers,
Ranga:-)
# 7  
Old 04-01-2012
hi rangarasan/Scrutinizer,

I have this problem. This reply is not working. here is complete ..

Code:
/Users/ssthomas/ $cat file

12222     AUH         FLUEH
12222     SSC          OPERA
12222     SSC          OPERA
12223     SSC          OPERA
12223     SSC          OPERA
12223     AUH          FLUEH
12223     SSC          FLORE 
12223     SSC          FLORE

Output soaking -

Code:
12222     SSC-2 AUH-1 OPERA-2 FLUEH-1
12223     SSC-4 AUH-1 OPERA-2 FLORE-2 FLUEH-1

or atleast this...

Code:
12222     SSC-2 AUH-1 
12223     SSC-4 AUH-1

--- here --

Code:
/Users/ssthomas/ $awk 'BEGIN{ORS="";f[1]="AUH";f[2]="FLUEH";f[3]="SSC";f[4]="OPERA";f[5]="FLORE";}{a[$1"^"$2]  ;a[$1"^"$3]  ;c[$1]=1;}END{for(i in c){print i;for(j=1;j<=length(f);j  ){fld=f[j];if(a[i"^"fld]){print fld"-"a[i"^"fld];}}print "\n";}}' file
awk: can't open file file
 source line number 1

/Users/ssthomas/ $

-- Please help here.
Thank you.
Sebastian

Last edited by Scrutinizer; 04-01-2012 at 08:19 PM.. Reason: Please Use [code] tags [/code], thank you..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

4. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

5. Shell Programming and Scripting

Consolidate several lines of a CSV file with firewall rules, in order to parse them easier?

Consolidate several lines of a CSV file with firewall rules Hi guys. I have a CSV file, which I created using an HTML export from a Check Point firewall policy. Each rule is represented as several lines, in some cases. That occurs when a rule has several address sources, destinations or... (4 Replies)
Discussion started by: starriol
4 Replies

6. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

7. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

8. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

9. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

10. Shell Programming and Scripting

Logfile parsing with variable, multiple criterias among multiple lines

Hi all I've been working on a bash script parsing through debug/trace files and extracting all lines that relate to some search string. So far, it works pretty well. However, I am challenged by one requirement that is still open. What I want to do: 1) parse through a file and identify all... (3 Replies)
Discussion started by: reminder
3 Replies
Login or Register to Ask a Question