Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED and pattern matching 1

Status
Not open for further replies.

motoslide

MIS
Oct 30, 2002
764
US
I'm sure this is an easy one for the SED folks: Please enlighten me, or point to an existing POST. I tried to search (honest), but didn't find anything close enough:

I have a text file with very predictable patterns:
(example)
Revision: 1.1.3.4
Revision: 1.2.2.1
Revision: 1.18.2.1
Revision: 1.6
Revision: 1.12

I wish to delete any lines that have the four sets of numbers, but keep all those that have fewer. I want my output to contain only:

Revision: 1.6
Revision: 1.12

This is the sed section of my script:
Code:
sed '/[0-9].[0-9].[0-9].[0-9]/d' "mod_list" >"mod_list.tmp"          
sed '/[0-9].[0-9][0-9].[0-9].[0-9]/d' "mod_list.tmp" >"mod_list.tmp2"

For the limited example above, I get the results I want. But, there will come a time where the 1st, 3rd, and/or 4th numeric will be 2 digits. What is the better 1-line syntax to accomplish my goal?

Thanks in advance for the help!
 
Something like this ?
awk -F. 'NF!=4' mod_list

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just to answer the sed version, it would be like this...
Code:
sed '/[0-9]*.[0-9]*.[0-9]*.[0-9]*/d' "mod_list" > "mod_list.tmp"
The asterisk ([tt]*[/tt]) in this case means, "one or more of the previous character", so that will catch a number of any number of digits.

Hope this helps.
 
Thanks.
I knew there had to be a clean "sed" way to accomplish this task. If I end up having to look specifically for numerics, this will be handy. For now, simply looking for the presence of 4 fields (using the awk syntax from PHV) serves my needs.

I appreciate the follow-up, though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top