help with grep the pattern


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
help with grep the pattern

I have those lines in a file:

:startStr xxxxxxx(anything) STRING1 xxxxxx
startStr xxxxxxx STRING1 xxxxxxxxxxxxx
startStr xxxxxxxxx STRING2 xxxxxxxx
.......

grep only the lines starting "startStr" (without ":") & with "STRING1"
-e.g. the second line in the above file

I use the following which works but how to also include the "startStr"??
grep '^[^:]*STRING1' *

Thanks!!
# 2  
Better of with a sed solution

Code:
sed -n -e "s/^startStr.*STRING1.*$/&/p" input.txt

grep-wise this may work.

Code:
grep -e "^StartStr.*STRING1" input.txt

# 3  
thanks vino!!
Both work, with a little mod (on SunOS)- the " " => ' ', & leave -e out of the grep.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #736
Difficulty: Medium
In 1982, Commodore introduced the Commodore 64 as the successor to the VIC-20.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

Grep lines before a pattern having some other pattern

Hi All, I am trying to fetch lines before a pattern, I got to know about -B flag in grep but we have to pass the number to get those lines before some pattern say (X), now what if I want to get line/s with some other pattern say (Y) before X pattern? How to get about it? please help. Input:... (5 Replies)
Discussion started by: dips_ag
5 Replies

4. 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

5. Shell Programming and Scripting

How to Grep than scan line below grep pattern

Hello Colleagues, I have a file that looks like below. 6-12731913-12731913 9230760143480 410018547148230 20131002193434+0500 20131002193434+0500 ;20131002T161031000-10.50.241.21-21912131-1419034760, ver: 0 20131009 92220056296730 CC0P abc Core_Context_R1A SMS 6-12726796-12726796... (14 Replies)
Discussion started by: umarsatti
14 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. UNIX for Dummies Questions & Answers

How to grep this pattern?

Guys, I have a certain pattern of string in one of my logs. The pattern is below: 07:42:56,613 INFO :: TracingMyNewMessage: 35=849=OOPLKCV56=YYUNBHJ57=uujhio2=20120612-11:42:56.613128=OOIUJKJN150=020=011=_poiu88785=X32=044=106=031=554 (the above is one continious line) I do a grep like... (2 Replies)
Discussion started by: DallasT
2 Replies

8. UNIX for Dummies Questions & Answers

How to grep pattern

Hi All, I need to grep pattern from text file. Also, I need to print above 3 lines from where the pattern starts. For expample, in the below texts, I need to grep "ORA-00600" and also the date, which will tell, on which date, the error belongs to? I hope, I am able to clarify my points.. ... (2 Replies)
Discussion started by: alok.behria
2 Replies

9. Shell Programming and Scripting

Want to grep for a pattern and display the content above that pattern

Hi, When we have a failure, sometimes we just step restart the job from the next step. Later when we open the log for analysis of the failure, it is becoming difficult to go to the failure part. For eg., if it is a 1000 line log, the failure may be at 500th line. so wat i want to do is, grep... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

10. Shell Programming and Scripting

how to grep certain pattern

-Hi I have a file with the following entries: tschkback12 tschkback11 tschkback15 tschkback28 ....etc. I need to grep all the lines out of this file which end with the number (just "tschkback" should be excluded). Can it be done with one line command? Thanks -A (5 Replies)
Discussion started by: aoussenko
5 Replies

Featured Tech Videos