Grep with regulare expression to find carrige return


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep with regulare expression to find carrige return
# 1  
Old 06-22-2011
Grep with regulare expression to find carrige return

Gurus,

I have a files from where lines are like following


<ns0:ccid>123456789</ns0:ccid>

<ns0:ccid>1234
56789</ns0:ccid>

I would like to grep any number which will be as below (with carrige return): As 123456789 any number so I have to use the regular expression

<ns0:ccid>1234
56789</ns0:ccid>
# 2  
Old 06-22-2011
Code:
perl -ln0e '$,="\n";print /^.*\d+\n\d+.*$/gm' file

# 3  
Old 06-22-2011
But that would match any
Code:
<tag>1234
567890</tag>

You could be more specific:
Code:
perl -ln0e '$,="\n"; print /^<ns0:ccid>\d+\n\d+<\/ns0:ccid>$/gm' file

to match only <ns0:ccid> tags
# 4  
Old 06-22-2011
Quote:
Originally Posted by bartus11
Code:
perl -ln0e '$,="\n";print /^.*\d+\n\d+.*$/gm' file

I need to add the following string <ns0:ccid> . It will be like "<ns0:ccid>***\n</ns0:ccid>" Here \n --> carrige return. *** --> any number
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 expression

im trying to find the best way to match an expression using grep. input file is <html>word word word word.</a> <html>word word word word word word .</a> <html>word word word word word word word word .</a> <html>word word word word word word word word word word word word word word word word... (4 Replies)
Discussion started by: ahfze
4 Replies

2. UNIX for Dummies Questions & Answers

awk If expression - Return string if not true

Hi, I have the following txt file List_With_Duplicates.txt; a,1,1 b,3,4 c,5,2 d,6,1 e,3,3 f,3,7 When I run the command awk -F ',' '{if($2==$3){print $1","$2","$3}}' List_With_Duplicates.txt I get the following output; a,1,1 e,3,3 This works! as I've compared the 2nd & 3rd... (7 Replies)
Discussion started by: mmab
7 Replies

3. UNIX for Dummies Questions & Answers

Grep to find matching patern and return unique values

Request: grep to find given matching patern and return unique values, eliminate the duplicate values I have to retrieve the unique folder on the below file contents like; /app/oracle/build_lib/pkg320.0_20120927 /app/oracle/build_lib/pkg320.0_20121004_prof... (5 Replies)
Discussion started by: Siva SQL
5 Replies

4. Shell Programming and Scripting

Find, regular expression, anyway to simplify this find command?

Hello everyone, first post here, trying to learn scripting on my own and this forum as been really helpful so far. I made few little scripts working great but I m facing some problems with RE. I have a bunch of files in many subdirectories called *001.ext *002.ext OR simple *.ext or *01.ext... (7 Replies)
Discussion started by: Sekullos
7 Replies

5. UNIX for Advanced & Expert Users

return of grep

Hi, in a script I will do : grep ORA- mylogfile.log If it returns any ORA- (oracle error) I whant to have : echo "subject : RMAN in Error " >> /appli/rap.txt But if no error echo "subject : RMAN OK " >> /appli/rap.txt Can you help me ? The grep return code would it be... (1 Reply)
Discussion started by: big123456
1 Replies

6. Shell Programming and Scripting

Using grep and regular expression to find class references in a c++ file

I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working... (0 Replies)
Discussion started by: passerby
0 Replies

7. UNIX for Dummies Questions & Answers

grep regular expression to find = not ==

I suspect this is commonly done, but haven't found the right combination of search terms to find the answer. I want to grep for lines in .cpp files that contain only 1 '=' sign in an if statement. e.g., if (a = b) -- find this if (a==b) -- don't find this My attempt: egrep... (7 Replies)
Discussion started by: offkilter
7 Replies

8. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

9. Shell Programming and Scripting

supressing carrige returns/line feeds

Hi gurus I am stripping lots of email addresses from a file with this grep "^To" file.log |awk '{print "1,"$2}' > recipients.out file.log looks something like this: oasndfoasnosf To: person@email.co.uk lsdfjosd sdlfnmsopdfwer dtlghodrgn To: person2@emailsss.com sldfnsdf I... (5 Replies)
Discussion started by: terry2009
5 Replies

10. UNIX for Dummies Questions & Answers

GREP expression

I'm strugling with an expression for grep which I hope someone will be kind enough to help me with. I'm attempting to isolate those processes which have run for more than a specified time (half a second at the moment). Script so far: ps -ef | grep '*:5' The issue is that it's picking up my... (2 Replies)
Discussion started by: kutz13
2 Replies
Login or Register to Ask a Question