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
Regular Expression to match repeated characters jambesh Shell Programming and Scripting 4 08-22-2009 01:51 AM
Regular Expression - Replace if x contains y except if... not4google UNIX for Dummies Questions & Answers 4 03-04-2009 03:36 PM
Replace if regex on specific column matches expression? EXT3FSCK Shell Programming and Scripting 5 11-25-2008 02:00 PM
Want to replace characters arndorff Shell Programming and Scripting 5 01-29-2008 04:05 PM
Replace Characters... lgardner17325 UNIX for Dummies Questions & Answers 8 10-26-2006 06:04 PM

Reply
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 09-03-2009
poldo poldo is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 7
Talking Sed replace characters not equal to an expression

Hi all,

Suppose I have a file with the contents below, and I only want to print words %S_[A-Z] then | sort -u.


------------------------------
The %S_MSG that starts with '%.*s' is too long. Maximum length is %d.
The %S_MSG name '%.*s' contains more than the maximum number of prefixes. The maximum is %d.
The size (%d) given to the %S_MSG '%.*s' exceeds the maximum. The largest size allowed is %d.
%S_MSG is not allowed in %S_MSG.
The %S_MSG '%.*s' is out of the range of machine representation (%d bytes).
'%.*s' is not a recognized %S_MSG.
%s permission denied on object %S_OBJID, database %S_DBID, owner %.*s
%s permission denied on column %.*s of object %S_OBJID, database %S_DBID, owner %.*s
The column %.*s in table %.*s does not allow null values.%S_EED
Precision error during %S_MSG conversion of %s value '%s' to a %s field.
Scale error during %S_MSG conversion of %s value '%s' to a %s field.
Domain error during %S_MSG conversion of %s value '%s' to a %s field.
Arithmetic overflow during %S_MSG conversion of %s value '%s' to a %s field .
Syntax error during %S_MSG conversion of %s value '%s' to a %s field.
%s permission denied, database %S_DBID, owner %.*s
------------------------------------------

I'm trying to get the output like below
%S_MSG
%S_DBID
...
...

Problem is i don't know how many characters there are after the %S_, only that these are all caps.

I'm kind of new here also and any help is appreciated. I usually go here to look for help and tips in scripting.

Thanks
  #2 (permalink)  
Old 09-03-2009
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
sounds like you want something like:

Code:
#  sed 's/.*\(%S_[A-Z]*\).*/\1/g' file1 | sort -u
%S_DBID
%S_EED
%S_MSG
HTH
  #3 (permalink)  
Old 09-03-2009
poldo poldo is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 7
Wow that's just awesome! I've been trying different things and never came up with one working. Thanks!
  #4 (permalink)  
Old 09-03-2009
malcomex999 malcomex999 is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 151
Actually after %S_, you are also having dot and comma after the capital letters but try this if it helps
Code:
 
sed 's/.*\(\%S\_[A-Z]*[ |\,|\.]\).*/\1/' infile | sort -u
  #5 (permalink)  
Old 09-03-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,880
Code:
perl -e 'while(<>){ while(/(%S_[A-Z]+)\b/g){ $seen{$1}=1;}} foreach (sort keys %seen){print $_,"\n";}' test.txt
%S_DBID
%S_EED
%S_MSG
%S_OBJID
  #6 (permalink)  
Old 09-10-2009
poldo poldo is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 7
hey, thanks pludi. although i'm not that familiar with pearl.
Reply

Bookmarks

Tags
print, replace, sed, words

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 09:30 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