Help with Grep pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Grep pattern
# 1  
Old 07-25-2013
Help with Grep pattern

Hello Admin,
i need a grep pattern for the following requirement, Could you pls help.

Used Grep pattern : egrep "^[+-]([^+-].*|)$" inputfile

i have input file:
Code:
+
++++
-
------
+jfsfkjf
+ * @param node <96> node to generate the configuration file(s) for
+ * @param dir <96> root directory under which to place the generated files.
+ *              If active configuration is modified at run-time this will point
+ *              to /etc. Otherwise it may point to a saved configuration volume.
+ * @param ptr <96> event receiver handle, can be used to e.g. query the events
+ *              occurred in the context of the last transaction.
+ * @param ldap_handle <96> handle of an active LDAP connection.

output of the grep should contain all the lines of input file except :
Code:
++++
-----

But my grep pattern is not able to get the "@param" lines, Could yo upls help me improving the grep pattern to include that as well.

Last edited by Don Cragun; 08-01-2013 at 06:28 AM.. Reason: Add CODE and ICODE tags
# 2  
Old 07-25-2013
On my ubuntu, I get the same result with
Code:
egrep "^[+-]([^+-].*|)$"
and
awk '!/^\+\+\+\+|^-----/'

Code:
+
-
+jfsfkjf
+ * @param node <96> node to generate the configuration file(s) for
+ * @param dir <96> root directory under which to place the generated files.
+ * If active configuration is modified at run-time this will point
+ * to /etc. Otherwise it may point to a saved configuration volume.
+ * @param ptr <96> event receiver handle, can be used to e.g. query the events
+ * occurred in the context of the last transaction.
+ * @param ldap_handle <96> handle of an active LDAP connection.

# 3  
Old 07-25-2013
Thanks for replying,
pls find my output below, where i'm not able to find the mentioned required lines:

Code:
$ grep "@param" delete
+            * @param alarmState state of alarm.
+            * @param eventType Event type of alarm to set.
+            * @param alarmEventType Alarm event type.
+            * @param AlarmEvent : ALarm from LAS to read and set to COMA alarm
+        *      @param none
+        *      @param none
+        *      @param string& value Attribute to be filled
+        *      @param none
+        *      @param - map<string,string> &p_values, Values fetched from LDAP.
+        *      @param - LDAP *ldap,
+        *      @param - vector<DNInfoAttributes> &dnAttributes,
+        *      @param - map<string,string> &values,
+ * @param node  node to generate the configuration file(s) for
+ * @param dir  root directory under which to place the generated files.
+ * @param ptr  event receiver handle, can be used to e.g. query the events
+ * @param ldap_handle  handle of an active LDAP connection. This connection
$ grep "@param" delete | wc -l
16



Code:
$ egrep "^[+-]([^+-].*|)$" delete | grep "@param"
+            * @param alarmState state of alarm.
+            * @param eventType Event type of alarm to set.
+            * @param alarmEventType Alarm event type.
+            * @param AlarmEvent : ALarm from LAS to read and set to COMA alarm
+        *      @param none
+        *      @param none
+        *      @param string& value Attribute to be filled
+        *      @param none
+        *      @param - map<string,string> &p_values, Values fetched from LDAP.
+        *      @param - LDAP *ldap,
+        *      @param - vector<DNInfoAttributes> &dnAttributes,
+        *      @param - map<string,string> &values,
$ egrep "^[+-]([^+-].*|)$" delete | grep "@param" | wc -l
12

Pls help.

Regards,
Chandana

Last edited by Don Cragun; 08-01-2013 at 06:30 AM.. Reason: CODE tags
# 4  
Old 08-01-2013
I can't tell whether the shifts between bold and non-bold is supposed to show us something in the output and if it is an indication that your input file has markings at the start of each bold line to make it appear in bold.

You have shown us two output files, but you haven't shown us the input file. Without knowing what the input is, it is hard to guess why you think the output produced is incorrect. The output you showed in the last message certainly didn't come from the file in your 1st posting in this thread.

And, PLEASE use CODE tags when showing us sample code, sample input, and sample output.
Login or Register to Ask a Question

Previous Thread | Next Thread

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. Emergency UNIX and Linux Support

Grep pattern

I have to search from millions of lines of code of lines having following pattern: get_token , get_token For example: fn1(string.get_token(), string1.get_token()); Thanks in advance (5 Replies)
Discussion started by: uunniixx
5 Replies

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

9. Shell Programming and Scripting

how to grep the pattern ?

how to grep the pattern ? How can I grep or find the pattern from this files in the directory. I have couple of ascii files too.I have to grep the binary files.Please assist me Thanks Francis (2 Replies)
Discussion started by: faviji
2 Replies

10. Shell Programming and Scripting

How to grep this pattern??

Hi All, I have a file like this, from this file I want to grep only this "package com.att.com;".... even though spaces are present at starting of the line. i.e., the o/p should ignore these two lines from the file : asdasdasd package ; ignore this line asdasdasd adsfkl90-9-0 package... (13 Replies)
Discussion started by: askumarece
13 Replies
Login or Register to Ask a Question