select a line that contains the strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting select a line that contains the strings
# 1  
Old 10-14-2008
Java select a line that contains the strings

hi
i have a file, from the file i need to extract the lines that contains both 17 and Received msg string, i used
cat <filename> | grep 17 | grep "Received msg" > <new file>

but it is not giving the required o/p

please help

thanks in advance
Satya
# 2  
Old 10-14-2008
bijayant@bijayant ~ $ cat test
hi this is bijayant 17
Received message 17
17 Received message
18 Received message
19 Received message
Bijayant Received message
Bijayant 17 Received message
17 Received message

bijayant@bijayant ~ $ grep -i "17.Received message\|Received message.17" test
Received message 17
17 Received message
Bijayant 17 Received message
17 Received message
# 3  
Old 10-14-2008
Quote:
Originally Posted by Satyak
.. extract the lines that contains both 17 and Received msg string..
Code:
awk '$0 ~ /17/ && $0 ~ /Received message/' file

# 4  
Old 10-14-2008
Hammer & Screwdriver Without seeing the problem data grep returned...

The previous two messages provide examples of code to find your lines from the file. The other issue that sometimes is a problem is in finding the number 17 since it can be part of 617 and 179. Thus, you may need to modify the grep for this to one of the following:
" 17 "
"17 "
" 17"

Depending on where you expect the 17 to be on the line, you might want to force a space character before/after or both.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. Shell Programming and Scripting

Select only line numbers using grep

Hai, I want to select only line numbers into a file if some pattern matches. I have written my script like below but its not working. #!/bin/sh file='/home/testfile1' filesearch='/home/test00' while read line do search=`echo $line |cut -c 1-24` echo $search echo `grep -n ""... (3 Replies)
Discussion started by: Subbu123
3 Replies

3. Shell Programming and Scripting

PS3 and SELECT, is it possible to put a line break?

Hi all, Before I give up on using SELECT for my first attempt at creating a menu driven script, can anyone please advise if it is possible to include a line break for PS3, I've tried putting in a \n and it does not work. Tried for both bash and ksh and both gives the same result. Preference... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. Shell Programming and Scripting

Select only the last line from the pattern

Hi, I am really new in the shell script, but it is really useful for me to learn. I have one question, I have a large text document (actually few of them), inside there are lines with information about energies, between 10 to 20 of this lines, varies from one doc to another one, my questions... (11 Replies)
Discussion started by: hmartine1983
11 Replies

5. Shell Programming and Scripting

select entry from consecutive line awk

Hi folks, I have a file with four columns that looks like the following (tab separated) 1 1 1 a 2 2 2 b 3 3 3 c 4 4 4 d I would like to create a file with always 4 columns but where the third entry corresponds to the thirst entry of the next line and so on, to get the following 1 1 2 a... (4 Replies)
Discussion started by: klebsiella
4 Replies

6. Shell Programming and Scripting

How to Select or cut from the certain filed to the end of the line

Hi: I have few rows in file..Like suppose... 9063C0 44 00051363603253033253347 3333 070248 06 9063C0 5G PAN00013 9063C0 44 00061030305040404250724 0506 100248 08 9063C0 43 01 00000089 I need to cut the row starting after... (5 Replies)
Discussion started by: grajesh_955
5 Replies

7. Shell Programming and Scripting

awk program to select a portion of a line

Hi all, I am new to awk programs.I have a file like this vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd vjfavhjlaf<LTEXT>aabcdfffvvbbxbcddjbv</LTEXT>fAFdfdADfd... (3 Replies)
Discussion started by: anju
3 Replies

8. UNIX for Dummies Questions & Answers

How to select line by line in shell

Hi, This is what the file data.lst contains. aaaaaaaa eeeeeeeeeeeeeeee 4444444 rrrrrrrrrrrrr tttttttttttt bbbbbbbb eeeeeeeeeeeeeeee 7777777 uuuuuuuu eeeeeeeee qqqqqqqq gggggggggggggggg 6666666 oooooooo ppppppppp Here I want to cut the third field and put it in a new file ... (15 Replies)
Discussion started by: preethgideon
15 Replies

9. Shell Programming and Scripting

awk to select a column from particular line number

The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line . Any help is appreciated. thanks arif (4 Replies)
Discussion started by: mab_arif16
4 Replies

10. Shell Programming and Scripting

How to select strings with space?

Hi folks, I have the following select function: select_vs_plugin() { export VS_LIST=`cat VsList.lst` while ] do echo echo echo =================================================================== ============ echo Please select Video Server Plugin ... (4 Replies)
Discussion started by: nir_s
4 Replies
Login or Register to Ask a Question