pattern checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pattern checking
# 1  
Old 06-23-2008
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  
Old 06-23-2008
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  
Old 06-23-2008
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  
Old 06-28-2008
hi,

thanks a lot... it works perfectly..

@fpmurphy

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

Krips.Smilie
# 5  
Old 06-29-2008
!{=;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  
Old 06-29-2008
thanks a lot ...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. Shell Programming and Scripting

Checking for pattern and merging files

I am trying to perform the following action. 1. A script runs the 'last' command for some users and prints the output to a file. $ cat last_users.log oracle pts/17 10.120.xxx.xxx Jun 28 14:42 - 18:01 (03:19) oracle pts/11 10.120.xxx.xxx Jun 28 14:28 - 20:17... (2 Replies)
Discussion started by: Nagesh_1985
2 Replies

3. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

4. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

5. Shell Programming and Scripting

Checking a pattern in file and the count of characters

I am having a zipped file which has the following URL contents - 98.70.217.222 - - "GET /liveupdate-aka.symantec.com/1340071490jtun_nav2k8enn09m25.m25?h=abcdefgh HTTP/1.1" 200 159229484 "-" "hBU1OhDsPXknMepDBJNScBj4BQcmUz5TwAAAAA" "-" In this line here is we only need to consider the... (4 Replies)
Discussion started by: Naks_Sh10
4 Replies

6. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

9. Shell Programming and Scripting

Checking existence of file using file pattern

Hi Experts:), I need to check the existense of file using patterns.How can i do it? Ex: if my current directory has a number of files of pattern (ins_*), i need to check the existense of atleast one file. pls reply me. (3 Replies)
Discussion started by: spkandy
3 Replies

10. UNIX for Dummies Questions & Answers

Checking for a file in file pattern before deleting it

Hi, I need a script where I have delete all the files of type abc*.* from the directory /lmn/opq (passed as parameter to script) But I need to check if there is file of type abc*.* existing in the directory or not before I use the rm abc*.* command. Thanks (1 Reply)
Discussion started by: dsrookie
1 Replies
Login or Register to Ask a Question