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
Changing one column of delimited file column to fixed width column manneni prakash Shell Programming and Scripting 5 06-22-2009 06:27 AM
Grep strings from file and put in Column thepurple Shell Programming and Scripting 2 12-08-2008 03:50 AM
Deleting column from a flatfile with delimiter rsprabha Shell Programming and Scripting 5 10-03-2008 05:18 AM
Delete repeated nos in a file gini UNIX for Dummies Questions & Answers 2 09-02-2008 04:07 PM
Get rid of repeated entries. jijibabawu Shell Programming and Scripting 2 10-03-2005 11:17 PM

Closed Thread
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
  #1 (permalink)  
Old 05-24-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Deleting repeated strings in column 2

Hi to all,

I have a file where the subject could contain "Summarized Availability Report" or only "Summarized Report"
If the subject is "Summarized Availability Report" I want to apply it Scrip1 and if the subject is "Summarized Report"
I want to apply it Scrip2.

1-) I would like you help me how to choose Script1 if Subject contains "Summarized Availability Report".
2-) To develop part of this Script1.

The Inputfile in $2 has strings with 2 or 3 between "_M" and "X-Z".

Code:
 
 
Inputfile example when Subject contain the string "Availability":
Subject: Summarized Availability Report
Comment             GHH_M55X            May 21 2009 4:45PM 
Comment             GHH_M55Y            May 21 2009 4:45PM
Comment             GHH_M55Z            May 21 2009 4:45PM
Comment             YUP_M19Y            May 18 2009 7:45PM
Comment             YUP_M19Y            May 18 2009 7:45PM
Comment             WON_M123X           May 17 2009 11:22AM
Comment             CET_M123X           May 15 2009 9:12AM

Desired output:
(Script1_part 1: After line containing "Subject:...", delete last letter of strings in $2)
(With my knowledge I got this
Code:
awk -F"[X-Z] " '/M[0-9][0-9]|[0-9][X-Z]/ {print $1" "$2}')


Code:
 
Subject: Summarized Report
 
Comment             GHH_M55            May 21 2009 4:45PM 
Comment             GHH_M55            May 21 2009 4:45PM 
Comment             GHH_M55            May 21 2009 4:45PM 
Comment             YUP_M19            May 18 2009 7:45PM 
Comment             YUP_M19            May 18 2009 7:45PM 
Comment             WON_M123           May 17 2009 11:22AM
Comment             CET_M123           May 15 2009 9:12AM

(Scrip1_part 2: After line containing "Subject:...", delete lines with repeated elements in $2)
(In this part I need help, I don´t know how to eliminate repeated strings in column 2 )

Code:
Subject: Summarized Report
Comment             GHH_M55            May 21 2009 4:45PM 
Comment             YUP_M19            May 18 2009 7:45PM
Comment             WON_M123           May 17 2009 11:22AM
Comment             CET_M123           May 15 2009 9:12AM

(Script1_part 3: After line containing "Subject:...", delete $1 and join lines with their Subject line)
Code:
 
Last lasta result 
Subject: Summarized Report->GHH_M55 May 21 2009 4:45PM, YUP_M19 May 18 2009 7:45PM, WON_M123 May 17 2009 11:22AM, CET_M123 May 15 2009 9:12AM

Thanks in advance for any help
  #2 (permalink)  
Old 05-25-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
To Remove the repeated lines and to print one copy .


Code:
awk '/^Comment/ { print $1,substr($2,1,length($2)-1),$3,$4,$5,$6 }' inputfile.txt | uniq -ud

  #3 (permalink)  
Old 05-25-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514

Code:
awk 'NR==1{printf("%s-->",$0)}/^Comment/{a[$2]=$2" "$3" "$4" "$5" "$6}END{for (i in a) printf("%s%s", a[i],OFS)}' OFS="," filename


-Devaraj Takhellambam
  #4 (permalink)  
Old 05-26-2009
cgkmal cgkmal is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 47
Hey guys, thanks for your help. I tested both solutions, but I would like to
do a mix between them.

For panyam solution I get unique lines but not joined like


Code:
 
Subject: Summarized Report->GHH_M55 May 21 2009 4:45PM, YUP_M19 May 18 2009 7:45PM, WON_M123 May 17 2009 11:22AM, CET_M123 May 15 2009 9:12AM

and for devtakh solution I get the solution like a joined sentence, but including repeated items.

I replace in your code the part

Code:
a[$2]=$2" "$3...

to
Code:
a[$2]=substr($2,1,length($2)-1)" "$3...

But from here I´m not sure how to present uniques lines in a joined sentence.

One more thing:

Assuming I have 2 scripts how to choose Script1 if "Subject" contains "Summarized Availability Report" within?

Thanks again,

Best regards
  #5 (permalink)  
Old 05-26-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474

Code:
But from here I´m not sure how to present uniques lines in a joined sentence.

use
Code:
"uniq -ud"

to get a single copy of the repeated lines.

Assuming I have 2 scripts how to choose Script1 if "Subject" contains "Summarized Availability Report" within?

that can be done by conditional checking.
  #6 (permalink)  
Old 05-26-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is online now Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,403
try devtakh's solution with small modification

Code:
awk 'NR==1{printf("%s-->",$0)}/^Comment/{a[substr($2,1,length($2)-1)]=$2" "$3" "$4" "$5" "$6}END{for (i in a) printf("%s%s", a[i],OFS)}' OFS="," filename

Closed Thread

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 11:32 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