execution problem with grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting execution problem with grep
# 1  
Old 12-13-2011
execution problem with grep

HTML Code:
how to use grep word from  sentence  

grep -o "hai" haighaihaihai

Is above cmd possible in linux ?

can any one help me?

Thanks,
# 2  
Old 12-13-2011
Quote:
Originally Posted by kavi.mogu
HTML Code:
how to use grep word from  sentence  

grep -o "hai" haighaihaihai

Is above cmd possible in linux ?

can any one help me?

Thanks,
Code:
echo "haighaihaihai" | grep -o "hai"

# 3  
Old 12-13-2011
error in grep.

HTML Code:
thx u so much.your comment is working fine.:):):):):)
---------- Post updated at 05:13 AM ---------- Previous update was at 05:01 AM ----------

HTML Code:
Is there any possibity to find assigned value using grep ?

(e.g) grep -o "i=1"  for(i=1;i<=10;i++)

I want to fetch "1" not  i=1(whole thing)
SmilieSmilieSmilieSmilie
# 4  
Old 12-13-2011
Quote:
Code:
grep -o "i=1"  for(i=1;i<=10;i++)

This is not how grep works. By default, grep takes a file as its input. Your code is telling grep to look in a file named "for(i=1;i<=10;i++)", which obviously won't work.

Instead, echo the text you are searching and pipe it to grep:

Code:
echo "for(i=1;i<=10;i++)"  | grep -o "i=1"

Alternatively, if the code you are searching is actually contained in a file, you can do

Code:
grep -o "i=1" file

Oh, and if you only want the value assigned to i:

Code:
echo "for(i=1;i<=10;i++)"  | grep -o "i=1" | awk -F= '{ print $2 }'

where "file" is the path to the file you are searching.
# 5  
Old 12-13-2011
One more way...

Code:
grep -o "i=1" <<<"for(i=1;i<=10;i++)"

man bash
Quote:
<<<word A short form of here document in which word becomes the contents of the here-document after
any parameter expansion, command substitution, and arithmetic substitution occur.
HTH
--ahamed
# 6  
Old 12-13-2011
grep commend

HTML Code:
code working fine..thx u  so much...:):):)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Execution problem

How to search a pattern from multiple files... i used the command suppose the pattern name is xxx grep xxx (file1-o- file2-o- file3) Thanks in advance (4 Replies)
Discussion started by: ksakil
4 Replies

2. Shell Programming and Scripting

Execution problem

Hi, I have been trying to run a simple script CONFIG_FILE="/jay/check" . . . for i in `cat $CONFIG_FILE` do loc=`echo $i | cut -d "|" -f2` var=$(find $loc -mtime -1|wc -l) if then echo $loc has files older than 1 day fi done . . . (2 Replies)
Discussion started by: jayii
2 Replies

3. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

4. UNIX for Dummies Questions & Answers

execution problem

HI I am trying to check the status of port using command /code: netstat -an | grep port /Output: *.2009 *.* 0 0 65535 0 LISTEN what i am trying to do is i want to grep only status Wether the port is established/listen if so show ok else... (1 Reply)
Discussion started by: esumiba
1 Replies

5. UNIX for Dummies Questions & Answers

execution problem

Hi I am automating my few commands out of which one command is tail -f running.logs when i run this command it does not automatically exit and show prompt (#) what would i do so that it will exit out automatically after few seconds and move to the next command without using ... (4 Replies)
Discussion started by: esumiba
4 Replies

6. UNIX for Dummies Questions & Answers

execution problem

Hi i have a file in which there are three fields code: 919804199233 404911130003916 357266044991350F and now i want to add two more fields i.e. code: 919804199233 404911130003916 357266044991350F ms 123 how can i do it using command line and if have a file of 100... (8 Replies)
Discussion started by: esumiba
8 Replies

7. UNIX for Dummies Questions & Answers

execution problem

Hi i am using expect module and trying to login using following code. ssh 127.0.0.1 expect "word:" send "$password \n" kindly let me know the login script using expect module (1 Reply)
Discussion started by: esumiba
1 Replies

8. Shell Programming and Scripting

Execution problems with grep command in scripting

Hi All, I was looking for grep command option which can exactly matches the word in a file, for examples you may be seeing one word that is also in another word, there might be lkk0lv23 and a lkk0lv234 in which case lkk0lv23 will put BOTH hosts from the grep in. I was using this in a bash... (2 Replies)
Discussion started by: bobby320
2 Replies

9. UNIX for Dummies Questions & Answers

Command execution in grep

I'm taking Unix Scripting course and we've been given the following command grep -l "`echo '\t'`" foo What this command is basically doing is giving the lines in the ordinary file foo that contains the letter 't'. From my understanding, command substation occurs first. So echo '\t' is... (2 Replies)
Discussion started by: kkhan00
2 Replies

10. Shell Programming and Scripting

Execution problem with grep script (2 variables)

#!\bin\sh TEST=test.log GREP=\usr\bin\grep $GREP -i 'dog\|cat' ${TEST} Why doesn't grep run at all? (10 Replies)
Discussion started by: jazzaddict
10 Replies
Login or Register to Ask a Question