How to print the extended regular expression ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print the extended regular expression ?
# 8  
Old 09-01-2011
Code:
sed -r 's/^[^ ]+ +([^ ]+ +[^ ]+).*$/\1/' INPUTFILE

# 9  
Old 09-02-2011
Can awk record the match result? FS==" " ,
Code:
2s    4s

so between 2s and 4s exists 4 spaces, the the match results is 4 spaces.
# 10  
Old 09-02-2011
gawk 4.0 can but
Quote:
The AWK utility is a data extraction and reporting tool
It's just not a right tool for you needs. You can do it in awk with a hand parsing using substr but this is not worth it.
# 11  
Old 09-04-2011
I have find a article, a chapter shows "Remembering patterns with \(, \) and \1" , does awk support it ?
# 12  
Old 09-04-2011
GNU awk supports backreferences with the gensub and match string builtin functions:

Code:
$ awk 'BEGIN {
  s="a b"
  print "gensub:", gensub(/(.+) (.+)/, "\\2 \\1", "g", s)
  match(s, /(.+) (.+)/, a)
  print "match:", a[2], a[1]
  }' 
gensub: b a
match: b a

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print byte position of extended ascii character

Hello, I am on AIX. When I encounter extended ascii characters and special characters on a file I need to print.. Byte position, actual character and line number. Is there a simple command that can give me the above result ? Thanks in advance (38 Replies)
Discussion started by: rosebud123
38 Replies

2. Shell Programming and Scripting

Grep command to search a regular expression in a line an only print the string after the match

Hello, one step in a shell script i am writing, involves Grep command to search a regular expression in a line an only print the string after the match an example line is below /logs/GRAS/LGT/applogs/lgt-2016-08-24/2016-08-24.8.log.zip:2016-08-24 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

3. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

Would like to print 3 lines after a regular expression is found in the logfile

I would like to print 3 lines after a regular expression is found in the logfile. I'm using the following code: grep -n "$reg_exp" file.txt |while read LINE ;do i=$(echo $LINE |cut -d':' -f1 ) ;sed -n "$i,$(($i+3))p" file.txt ;done The above code things works fine,but sometimes gives erroneous... (3 Replies)
Discussion started by: joachimshaun
3 Replies

6. Shell Programming and Scripting

Regular Expression.

can someone let me know what this means in english. \(abcd\) \ is an escape key right? Thanks Also im getting confused with something like it does this mean any single character? and this would be 2 characters ? Just let me know if im on the right track. (5 Replies)
Discussion started by: syco__
5 Replies

7. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

8. Shell Programming and Scripting

Regular expression in grep -E | awk print

Hi All, I have file.txt with contents like this: random text To: recipient@email.co.uk <HTML>S7randomtext more random text random text To: recip@smtpemail.com <HTML>E5randomtext more random text random text I need the output to look like this: 1,,,1,S7 1,,,1,E5 My code so... (9 Replies)
Discussion started by: terry2009
9 Replies

9. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

10. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies
Login or Register to Ask a Question