To Delete the repeated occurances and print in same line by appending values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Delete the repeated occurances and print in same line by appending values
# 1  
Old 06-25-2009
To Delete the repeated occurances and print in same line by appending values

Hi All,

I am trying to work on below text

a b c 1
a b c 2
a b c 3
x y z 6
x y z 44
a b c 89

Need to delete the occurances and get in single line like below:

a b c 1 2 3 89
x y z 6 44 89

Please help me i am new into unix scripting .....

---------- Post updated at 03:00 PM ---------- Previous update was at 02:55 PM ----------

Even when i try using a xcel pivot table to do this also doesnt help as output is something like this
abc 1
2
3
89
Xyz 6
44
89

Not getting in same row.......

How to use awk to get this
# 2  
Old 06-25-2009
Code:
awk '/a b c/ {t=t" "$4} /x y z/ {s=s" "$4} END {print "a b c" t;print "x y z" s}' inputfile

# 3  
Old 06-25-2009
Hey thanks but this is for only xyz and abc but my data file is huge with different patterns occuring many times....
# 4  
Old 06-25-2009
Code:
 
awk '{ a[$1" "$2" "$3" "]=a[$1" "$2" "$3" "]" "$4}END { for(i in a) print i,a[i]}' input_file.txt

# 5  
Old 06-25-2009
Check if this meets ur requirement...
Code:
/bin/sort inputfile | awk ' BEGIN { FS=OFS=" ";getline;prev=$1" "$2" "$3;s=$4 }

{
  curr=$1" "$2" "$3
#  print curr
  if ( prev == curr )
    s=s" "$4
  if ( prev != curr )
   {
   print prev " " s
   prev=curr;s=$4
   }
}
END {
   print prev " " s
}'

panyam's solution is cool and exact..
# 6  
Old 06-25-2009
why does "x y z" has an extra 89?
# 7  
Old 06-25-2009
Quote:
Originally Posted by ghostdog74
why does "x y z" has an extra 89?
Looks typo to me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Adding the values of repeated ids

File1 consist two columns, first some weired ids and second the numbers t|v203.1@t|k88711.1 0.1 t|v190.1@t|k90369.1 0.01 t|v203.1@t|k88711.1 0.5 t|v322.1@t|k88711.1 0.2 t|v207.1@t|k90369.1 0.11 t|v326.1@t|k85939.1 0.5 t|v207.1@t|k90369.1 0.7 t|v207.1@t|k90369.1 0.3 t|v326.1@t|k89421.1 0.33... (3 Replies)
Discussion started by: ashmit99
3 Replies

3. Shell Programming and Scripting

Print line if values in fields matches number and text

datafile: 2017-03-24 10:26:22.098566|5|'No Route for Sndr:RETEK RMS 00040 /ZZ Appl:PF Func:PD Txn:832 Group Cntr:None ISA CntlNr:None Ver:003050 '|'2'|'PFI'|'-'|'EAI_ED_DeleteAll'|'EAI_ED'|NULL|NULL|NULL|139050594|ActivityLog| 2017-03-27 02:50:02.028706|5|'No Route for... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

5. Shell Programming and Scripting

Reoccuring peak values in large data file and print the line..

Hi i have some large data files that contain several fields and rows the data in a field have a numeric value that is in a sine wave pattern what i would like todo is locate each peak and pick the highest value and print that complete line. the data looks something like this it is field nr4 which... (4 Replies)
Discussion started by: ninjaunx
4 Replies

6. Shell Programming and Scripting

Put repeated values into a table

Hi all, I have blocks of records like the following, each block ends in = in a new line, I want tabularize the entire output. The pattern is the same in every block although not all types are there in every block. For example gine3 is absent in the second block but present first and third. ... (7 Replies)
Discussion started by: ritakadm
7 Replies

7. Shell Programming and Scripting

Resume and count repeated values

Gents, Please can you help me. Input file 1050 , 9 ,9888 1050 ,10 ,9888 1050 ,11 ,9888 1050 ,13 ,9888 1050 ,15 ,9888 1051 , 9 ,9889 1051 ,12 ,9889 1051 ,15 ,9889 1051 ,18 ,9889 1052 , 9 ... (7 Replies)
Discussion started by: jiam912
7 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Print a line using a max and a min values of different columns

Hi guys, I already search on the forum but i can't solve this on my own. I have a lot of files like this: And i need to print the line with the maximum value in last column but if the value is the same (2 in this exemple for the 3 last lines) i need get the line with the minimum value in... (4 Replies)
Discussion started by: MetaBolic0
4 Replies

9. Shell Programming and Scripting

delete repeated strings (tags) in a line and concatenate corresponding words

Hello friends! Each line of my input file has this format: word<TAB>tag1<blankspace>lemma<TAB>tag2<blankspace>lemma ... <TAB>tag3<blankspace>lemma Of this file I need to eliminate all the repeated tags (of the same word) in a line, as in the example here below, but conserving both (all) the... (2 Replies)
Discussion started by: mjomba
2 Replies

10. UNIX for Dummies Questions & Answers

Delete repeated nos in a file

Hi, I need to delete repeated nos in a file and finally list the count. Can some one assist me? file: 12345 12345 56345 12345 23896 Output needed: 12345 56345 23896 Total count:3 Thanks (2 Replies)
Discussion started by: gini
2 Replies
Login or Register to Ask a Question