search line with more than two dots if so throw error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search line with more than two dots if so throw error
# 1  
Old 09-21-2010
search line with more than two dots if so throw error

Hi,
I have a requirement like i have to search a script and find names that conatins more than two dots, if so then throw error.

For ex: a1.b1.comname here i have to find comname and check two dots. it will not throw error

a1.b1.c1.comname here it contains more than 2dots it will throw error.

how i will do this.

Thanks in advance
# 2  
Old 09-21-2010
Code:
$ echo "a1.b1.comname" | ruby -e 'puts gets.count(".")>2 ? "error" : "ok"'
ok
$ echo "a1.b1.c1.comname" | ruby -e 'puts gets.count(".")>2 ? "error" : "ok"'
error

# 3  
Old 09-21-2010
Code:
$ echo "a1.b1.comname" |awk -F . '{print (NF>3)?"error":"OK"}'
OK

$ echo "a1.b1.c1.comname"  |awk -F . '{print (NF>3)?"error":"OK"}'
error

# 4  
Old 09-21-2010
Code:
for S in a1.b1.comname a1.b1.c1.comname
do
   P=${S//[^.]/}
   echo -n "$S : "
   [ ${#P} -le 2 ] && echo "OK" || echo "error"
done

Result
Code:
a1.b1.comname : OK
a1.b1.c1.comname : error

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to check and throw error for multiplication result

I need to multiply column1 and column3 data and need to compare it with column5. Need to check multiplication and Throw error if result is greater or less than column5 values, though difference of +/- 2 will be ok Ex - if column1 has 2.4 and column3 has 3.5, it will be ok if column5 have value... (13 Replies)
Discussion started by: as7951
13 Replies

2. Shell Programming and Scripting

Search first file line after Error and display

I have a log file which contains information like below (more than 200 ERROR sets). Here I want to find first .c file and function after "ERROR: AddressSanitizer" line. If you see here after "ERROR:" line first file - asfrecohandling.c function - ASFPotRecoHandling_Create_RecPaxSrvcComp ... (6 Replies)
Discussion started by: pushpabuzz
6 Replies

3. HP-UX

Debug3 messages throw in my terminal

OS: HP-UX B.11.31 U ia64 shell : /sbin/sh Messages like "debug3: Wrote 48 bytes for a total of 15837" are thrown in my terminal after each key stroke. If I try to type a command such message appears after each character I type. If I simply press enter messages like below appear. ... (1 Reply)
Discussion started by: black_fender
1 Replies

4. Shell Programming and Scripting

Search: find current line, then search back

Hello. I want to find a line that has "new = 0" in it, then search back based on field $4 () in the current line, and find the first line that has field $4 and "last fetch" Grep or Awk preferred. Here is what the data looks like: 2013-12-12 12:10:30,117 TRACE last fetch: Thu Dec 12... (7 Replies)
Discussion started by: JimBurns
7 Replies

5. What is on Your Mind?

Throw my Toys out of the Pram!

Hi Folks, Today hasn't been the best one of my career in IT. I've been a contractor for a major utility company for a number of years, on a number of seperate IT contracts mostly Unix. The company had 10 different flavours of unix and multiple different varsions of most of them. At the... (3 Replies)
Discussion started by: gull04
3 Replies

6. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

7. Shell Programming and Scripting

Find Command in the script throw error

Hi I have script that is developed to serch for 30 days old Directory & Files and then remove them ... when i run it successfully removes the Directory & files & but it throw errors on the screen .. .. + find . -type f -mtime +30 -exec rm -f {} ; + exit please help me ?? I... (0 Replies)
Discussion started by: Beginner123
0 Replies

8. UNIX for Dummies Questions & Answers

if a file is empty throw an error

I want to count the number of lines in a file and store it in a variable if this count is zero i hv to throw an error ...is this syntax correct , but i am not getting the desired result I am not using -s option here as i am concerned about record count not the size #!/bin/ksh set $count1... (4 Replies)
Discussion started by: mavesum
4 Replies

9. Shell Programming and Scripting

throw a generic message upon error

hi all, in ksh, is there a way to throw a generic error message. i have lots of commands in my script and i didnt want to put if ; then doStuff(); else print "an error occured, please run script again"; fi around all the commands used. is there a way detect a command has... (1 Reply)
Discussion started by: cesarNZ
1 Replies

10. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question