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
nawk-how count the number of occurances of a pattern, when don't know the pattern cyber111 Shell Programming and Scripting 2 05-11-2008 04:00 AM
Checking for a file in file pattern before deleting it dsrookie UNIX for Dummies Questions & Answers 1 05-09-2008 05:29 PM
SED Search Pattern and Replace with the Pattern racbern Shell Programming and Scripting 4 03-15-2008 05:59 AM
Pattern searching pattern in c files murthybptl Shell Programming and Scripting 6 11-17-2007 09:15 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 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 06-23-2008
kripssmart kripssmart is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 43
pattern checking

hi ,

i am having one file which is having the contents like this :

"1111111111"
"2222222222"
"4444232344"
...

i want to check if all the patterns in the file follows this sequence like starting with " ending with " inside that 10 digits...

can anyone help me in checking that..

thanks,

Krips.
  #2 (permalink)  
Old 06-23-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35

Code:
grep -E '^\"[[:digit:]]{10}\"$'

example:

Code:
# cat aaa | grep -E '^\"[[:digit:]]{10}\"$'
"1111111111"
"2222222222"
"4444232344"
# cat >bbb
"1111111111"
"2222222222"
"4444232d33"
"f666666666"
"6455"
# cat bbb | grep -E '^\"[[:digit:]]{10}\"$'
"1111111111"
"2222222222"

  #3 (permalink)  
Old 06-23-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
The following sed script will print out the line number and contents of any line that does not meet the pattern requirements.


Code:
#!/usr/bin/ksh

sed -n '/^"[0-9]\{10\}"$/!{=;p;}' file | \
sed '{
   N;
   s/\n/ /
}'

  #4 (permalink)  
Old 06-28-2008
kripssmart kripssmart is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 43
hi,

thanks a lot... it works perfectly..

@fpmurphy

can you please clear my doubt .. in that sed command what is !{=;p;} checking for..

Krips.
  #5 (permalink)  
Old 06-29-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
!{=;p;} means if a line does not match the regular expression i.e. exactly 10 digits, then print the line number followed by the line itself i.e.

Code:
10
FPM1234567

This output is then piped to a second invocation of sed which concatinates these 2 lines into a single line i.e.

Code:
10 FPM1234567

  #6 (permalink)  
Old 06-29-2008
kripssmart kripssmart is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 43
thanks a lot ...
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 08:28 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