to search for a particular character in a word


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to search for a particular character in a word
# 1  
Old 10-03-2008
to search for a particular character in a word

Hi
I would like to accept in a string from user like
username/pwd@dbname
suppose the user does not input @ then i should throw an error that @ symbol missing . How to achieve this

Thanks in advance
Suresh
# 2  
Old 10-04-2008
you can use this
Code:
 
echo "enter username and password"
read var
echo "$var"|grep "@" >> /dev/null
if [ $? -ne 0 ];then echo "no \"@\" found";else echo "\"@\" found";fi

# 3  
Old 10-04-2008
Quote:
Originally Posted by vidyadhar85
you can use this
Code:
 
echo "enter username and password"
read var
echo "$var"|grep "@" >> /dev/null
if [ $? -ne 0 ];then echo "no \"@\" found";else echo "\"@\" found";fi

The use of grep is not necessary i.e
Code:
#!/bin/bash

read -p "Enter username and password: " var
if [[ $var =~ "@" ]]
then
   echo 'found @'
else
   echo 'no @ found'
fi

# 4  
Old 10-04-2008
the use of regular expression in bash =~ is also not necessary
Code:
 case $input in *@*) 
    echo "there"
    echo "do something here"
    ;;
 esac

# 5  
Old 10-06-2008
Thanks guys for
# 6  
Old 10-06-2008
Thanks guys for ur replies
# 7  
Old 10-07-2008
Sorry for asking late actually i need to check for / also apart from @
I am using
echo "$var"|grep "@" >> /dev/null
as this worked for me

if i do like
echo "$3"|grep "\/*@" >> /dev/null
i am not getting desired result

is there another way
Thanks in advance
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. What is on Your Mind?

Updated Forum Search Index Min Word Length to 2 Chars and Added Quick Search Bar

Today I changed the forum mysql database to permit 2 letter searches: ft_min_word_len=2 I rebuilt the mysql search indexes as well. Then, I added a "quick search bar" at the top of each page. I have tested this and two letter searches are working; but it's not perfect,... (1 Reply)
Discussion started by: Neo
1 Replies

3. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

4. UNIX for Dummies Questions & Answers

Search for a particular word and replace the first character

Hi Unix gurus, I've a dna sequence in a file format known as fasta format (sequence header starts with > and ignored), an example shown below: >sequence_1 CGTATTCTCCGAATACC ATACG >sequence_2 CAGATTTTCAAATACCCCC In a file like this I want to do the following three search and replace. The... (4 Replies)
Discussion started by: Fahmida
4 Replies

5. Shell Programming and Scripting

[Solved] Search for a word and print the next word

Hi, I am trying to search for a word and print the next word. For example: My text is "<TRANSFORMATION TYPE ="Lookup Procedure">" I am searching for "TYPE" and trying to print ="Lookup Procedure" I have written a code like following: echo $line | nawk... (4 Replies)
Discussion started by: sampoorna
4 Replies

6. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

7. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

8. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

9. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

10. Shell Programming and Scripting

Command to parse a word character by character

Hi All, Can anyone help me please, I have a word like below. 6,76 I want to read this word and check if it has "," (comma) and if yes then i want to replace it with "." (dot). That means i want to be changed to 6.76 If the word doesnot contain "," then its should not be changed. Eg. ... (6 Replies)
Discussion started by: girish.raos
6 Replies
Login or Register to Ask a Question