LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-31-2012, 02:32 AM   #1
eyadgh
Member
 
Registered: Dec 2012
Posts: 40

Rep: Reputation: Disabled
my friends i need to complete this code


hello my friends i have this file .
i want code print words inside braces "ctr{ }" and if some words duplicate count it and then print the field $42 (in red color ) relate with "ctr { }" and for words duplicate find sum of $42 for it :

Expected output :

Code:
MishTabe3e     2  20
Mo7afazat      1  00
ZainUnlimited  1  23
ZainElKul      2  30
hint: " column 2 " is number of duplicate
i tried this code :

Code:
sed -n 's/.*ctr{\(.[^}]*\).*/\1/p' | sort|uniq -c
gave output:


Code:
MishTabe3e     2  
Mo7afazat      1  
ZainUnlimited  1  
ZainElKul      2

then i added :
Code:
sed -n 's/.*ctr{\(.[^}]*\).*/\1/p' | sort|uniq -c| nawk 'BEGIN{FS="|";s+=$42;print s}'
but didnt work .


cat file :


Code:
1|34|2012.12.01 00:08:35|12|4|100-10-0-962797849593|mar0101|0|00000104A20800000A6BD1C850B920280C00|0|0|400019FD7DBFBF7F|1001|962797849593|0|13039|||-1|796982870|00962796982870|16||-1|00962796982870|-1|0|2|0|416010000656446|0||||||0|0|2012.12.01 00:07:09|12|42|10|516|16|1|2012.12.01 00:06:27|1|0||202|1||0B12F1001104697209100300000000000000|1|1|11000|0|0||0881006972091003F000||0714F6100131BC69|000000000000|3|1|0000000000000000|0|10|0|0|0|0|0|0|||0|0|||||||||||||||||||||0|||0||0|1|144|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{MishTabe3e}cgpa{962797849593}vlr{0096279001300}cff{0}roaf{0}mpty{0}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||


1|34|2012.12.01 00:08:35|12|4|100-10-0-962797849593|mar0101|0|00000104A20800000A6BD1C850B920280C00|0|0|400019FD7DBFBF7F|1001|962797849593|0|13039|||-1|796982870|00962796982870|16||-1|00962796982870|-1|0|2|0|416010000656446|0||||||0|0|2012.12.01 00:07:09|12|42|10|516|16|1|2012.12.01 00:06:27|1|0||202|1||0B12F1001104697209100300000000000000|1|1|11000|0|0||0881006972091003F000||0714F6100131BC69|000000000000|3|1|0000000000000000|0|10|0|0|0|0|0|0|||0|0|||||||||||||||||||||0|||0||0|1|144|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{MishTabe3e}cgpa{962797849593}vlr{0096279001300}cff{0}roaf{0}mpty{0}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||


1|34|2012.12.01 00:08:35|12|4|100-10-0-962796057604|mar0101|0|00000107A20E00000A6C331650B920340C00|0|0|400019FD7DBFBF7F|1001|962796057604|0|01001|||-1|795971936|00962795971936|16||-1|00962795971936|-1|0|2|0|416019000659493|0||||||0|0|2012.12.01 00:07:09|12|30|0|516|16|1|2012.12.01 00:06:39|1|0||202|20001||0B12F1001104697209100300000000000000|1|1|11000|0|0||0881006972091003F000||0714F610045584E6|000000000000|3|1|0000000000000000|0|140|0|0|0|0|0|0|||0|2|||||||||||||||||||||0|||0||0|1|143|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{Mo7afazat}cgpa{962796057604}vlr{0096279001300}cff{0}roaf{0}mpty{0}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||





1|34|2012.12.01 00:08:35|12|4|100-10-0-962795292027|mar0101|0|00000101A20200000A6A96B750B920300C00|0|0|400019FD7DBFBF7F|1001|962795292027|0|01004|||-1|797196452|00962797196452|16||-1|00962797196452|-1|0|2|0|416018002276781|0||||||0|0|2012.12.01 00:07:09|12|12|23|516|16|1|2012.12.01 00:06:34|1|0||202|1||0B12F1001104697209100300000000000000|1|1|11000|0|0||0881006972091003F000||0714F6100455AD67|000000000000|3|1|0000000000000000|0|30|0|0|0|0|0|0|||0|0|||||||||||||||||||||0|||0||0|1|171|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{ZainUnlimited}cgpa{962795292027}vlr{0096279001300}cff{0}roaf{0}mpty{0}cacc{1;0;30}cquo{1;230;}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||





1|34|2012.12.01 00:08:35|12|4|100-10-0-962795622746|mar0101|0|00000103A20600000A6B8C7050B9203C0C00|0|0|400019FD7DBFBF7F|1001|962795622746|0|13069|||-1|96322398062|0096322398062|16||-1|0096322398062|-1|0|2|0|416011001866242|0||||||0|0|2012.12.01 00:08:46|12|18|15|516|3|1|2012.12.01 00:08:28|1|0||121|352||0B12F1001104697209100100000000000000|2|1|11000|0|0||0881006972091001F000||0714F610045EDC22|000000000000|3|1|0000000000000000|0|1850|0|0|0|0|0|0|||0|32|||||||||||||||||||||0|||0||0|1|143|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{ZainElKul}cgpa{962795622746}vlr{0096279001100}cff{0}roaf{0}mpty{0}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||



1|34|2012.12.01 00:08:35|12|4|100-10-0-962795622746|mar0101|0|00000103A20600000A6B8C7050B9203C0C00|0|0|400019FD7DBFBF7F|1001|962795622746|0|13069|||-1|96322398062|0096322398062|16||-1|0096322398062|-1|0|2|0|416011001866242|0||||||0|0|2012.12.01 00:08:46|12|18|15|516|3|1|2012.12.01 00:08:28|1|0||121|352||0B12F1001104697209100100000000000000|2|1|11000|0|0||0881006972091001F000||0714F610045EDC22|000000000000|3|1|0000000000000000|0|1850|0|0|0|0|0|0|||0|32|||||||||||||||||||||0|||0||0|1|143|acf{0}cif{0}fcf{0}con{0}cuf{0}ctr{ZainElKul}cgpa{962795622746}vlr{0096279001100}cff{0}roaf{0}mpty{0}ftksn{JMT}ftksr{0001}ftktp{CallTicketCPOCS}||

Last edited by colucix; 12-31-2012 at 06:04 AM. Reason: Added CODE tags
 
Old 12-31-2012, 03:23 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
gave output:

MishTabe3e 2
Mo7afazat 1
ZainUnlimited 1
ZainElKul 2

then i added :
sed -n 's/.*ctr{\(.[^}]*\).*/\1/p' | sort|uniq -c| nawk 'BEGIN{FS="|";s+=$42;print s}'
The output after 'uniq -c' consists only of 2 columns and it's the input data for your awk statement. In your awk statement you refer to column 42.
 
Old 12-31-2012, 05:44 AM   #3
eyadgh
Member
 
Registered: Dec 2012
Posts: 40

Original Poster
Rep: Reputation: Disabled
ooooh yes i dont how i can complete it
 
Old 12-31-2012, 05:58 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Moderator note: eyadgh, please use CODE tags to embed lines of code or the content of your files. This preserves space, indentation and therefore improve readability. Also it avoids very long lines to enlarge all the posts and stretch them horizontally. To use CODE tags either put [CODE] and [/CODE] before and after the code, respectively OR swithch to advanced mode, select your text and press the # button. Thank you in advance.
 
Old 12-31-2012, 06:03 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by eyadgh View Post
ooooh yes i dont how i can complete it
Have you understand what sycamorex told you? When trying out a pipeline, execute every command alone to fully understand what's the standard output and the standard input of every command. In this case the misbehaviour would be clear and exactly as sycamorex pointed out.
 
1 members found this post helpful.
Old 12-31-2012, 06:43 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Here is a solution in nawk only:
Code:
nawk 'BEGIN{FS = "|"} {s = $42; sub(/^.*ctr{/,""); sub(/}.*$/,""); c[$0]++; sum[$0] += s} END{for ( i in c ) printf "%-13s %2d %4d\n", i, c[i], sum[i]}' file
I don't remember what are the sorting functions in nawk (if any), hence you can easily pipe the output of the command above to
Code:
sort -k1
Is this what you are looking for? Any doubt about the suggested code?
 
2 members found this post helpful.
Old 12-31-2012, 07:44 AM   #7
eyadgh
Member
 
Registered: Dec 2012
Posts: 40

Original Poster
Rep: Reputation: Disabled
dear colucix
i dont know how to thank you you agreat programmar
thanks alot
 
Old 12-31-2012, 08:36 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to complete and install sourse code files. gardenair Linux - Software 13 01-29-2011 05:59 PM
writing complete code block in a terminal drmjh LQ Suggestions & Feedback 6 01-04-2011 02:35 PM
Image won't show - JAVA, complete code Nimoy Programming 5 11-01-2007 11:10 AM
complete source code. bruse Linux - Newbie 3 08-29-2005 06:10 PM
Applying a code patch to XFree without a complete rebuild? Locura Slackware 4 07-25-2003 06:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration