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. :slight_smile:

Thanks

sounds like you want something like:

#  sed 's/.*\(%S_[A-Z]*\).*/\1/g' file1 | sort -u
%S_DBID
%S_EED
%S_MSG

HTH

Actually after %S_, you are also having dot and comma after the capital letters but try this if it helps

 
sed 's/.*\(\%S\_[A-Z]*[ |\,|\.]\).*/\1/' infile | sort -u

Wow that's just awesome! I've been trying different things and never came up with one working. Thanks!

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

hey, thanks pludi. although i'm not that familiar with pearl. :smiley: