The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combining fields in two text fields shocker Shell Programming and Scripting 3 01-16-2008 11:27 AM
Cut Last 3 Fields bourne Shell Programming and Scripting 4 01-11-2007 05:17 AM
Last fields Khoomfire UNIX for Advanced & Expert Users 3 04-13-2006 06:03 PM
how to cut fields rajan_ka1 Shell Programming and Scripting 1 12-29-2005 05:55 AM
Awk - more than 99 fields? DaveM UNIX for Dummies Questions & Answers 2 01-23-2001 01:34 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 07-27-2008
DilipPanda DilipPanda is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 5
Deduplicate fields

Hi All,

I have a file which has the conetent like this:-
SELECT F1, F2, F3, F1, F5, F2 FROM T1
I Want to replace multiple occurences of F1 and F2 with single field.

Required Output Should be:
SELECT F1, F2, F3,F5 FROM T1

Please guide me how can i do this?

Thanks in Advance.
Dilip
  #2 (permalink)  
Old 07-27-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,915
Assuming your input file contains only select statements:


Code:
perl -lne'
  ($p1, $p2, $p3) = 
    /(SELECT )(.*?)( FROM .*)/;
  print $p1, 
    (join ", ", grep !$_{$_}++, split ", ", $p2), 
      $p3;
  undef %_' 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 04:59 AM.


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