Regular Expression for line

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regular Expression for line
# 1  
Old 06-03-2011
Regular Expression for line


I'm trying to extract if the (offset>0 || flags [MF] ) from the following line:

Code: > 90.121.333.308.45133: Flags [.], seq 14480:15928, ack 1, win 8088, options [nop,nop,TS[|tcp]>
15:59:11.156664 IP (tos 0x0, ttl 20, id 44442, offset 0, flags [DF], proto TCP (6), length 1500)


offset.([0-9]+) || flags.(.("MF"))

not getting result. Any suggestions
# 2  
Old 06-03-2011
What are you doing? Are you asking for help with grep, some programming language, or a third alternative I can't imagine yet?
# 3  
Old 06-03-2011
trying to get help with the regular expression writing ..
# 4  
Old 06-03-2011
Yes. Regular expression in what? grep? egrep? perl? sed? awk? They're not all the same.
# 5  
Old 06-03-2011

But I don't mind the help in awk
# 6  
Old 06-03-2011
See if this is working for you
awk '{match($0,/offset [0-9]+, flags .[A-Z][A-Z]./); print substr($0,RSTART,RLENGTH) } '

Last edited by Peasant; 06-04-2011 at 08:34 AM.. Reason: Typo in regex.
# 7  
Old 06-05-2011
I tried it but I'm still getting syntax error.

I'm trying to run the script over a file and I'm using the following syntax:

awk -f filename '{match($0,/offset [0-9]+, flags .[A-Z][A-Z]./); print substr($0,RSTART,RLENGTH) } '

Any suggestion!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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/ 19:12:48,602 ERROR... (9 Replies)
Discussion started by: Ramneekgupta91
9 Replies

2. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

3. Shell Programming and Scripting

Regular expression for 6 digit number present in a line

Hello Team, i have a file test1.txt, in which i have to grep only the 6 digit number from it, Could you pls help in this. $cat test1.txt <description>R_XYZ_1.6 r370956</description> $ grep "\{6\}" test1.txt <description>R_XYZ_1.6 r370956</description> i need output as 370956. ... (3 Replies)
Discussion started by: chandana hs
3 Replies

4. Shell Programming and Scripting

Extract regular expression and line below

Hi all, I have a large fasta (dna sequence) file. I would like to extract a portion of the header as well as the sequence (line below the header). Input: Output: All accession values (the term I want to preserve, which is the string including and directly following "GL") are different, but I... (8 Replies)
Discussion started by: pathunkathunk
8 Replies

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

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

7. Shell Programming and Scripting

Grep regular expression to get part of a line

Hi I just started on GNU Grep with regex and am finding it very challenging and need to ask for help already... here is the problem, I have a page (MYFILE) which consists of the following.... <div> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden"... (2 Replies)
Discussion started by: noobie74645
2 Replies

8. Shell Programming and Scripting

regular expression format string in one line.

Hi All, @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $day=091023; $day_combine = $day; $day_combine =~ s/({2})({2})({2})/20$1-$months-$3/; Instead of three lines, is possible to combine the last two lines into a single line? means no need assign $day to $day_combine... (2 Replies)
Discussion started by: jimmy_y
2 Replies

9. Shell Programming and Scripting

New line problem of regular expression

could anybody tell me how i can add/append a new line using regular expression in vi on AIX? i've tried several ways before, but all of them failed. e.g. :%s/$/\n/ :%s/^/\v\r/ :( (1 Reply)
Discussion started by: wrl
1 Replies

10. Shell Programming and Scripting

Regular expression matching a new line

I have written a script to test some isdn links in my network and I am trying to format the output to be more readable. Each line of the output has a different number of digits as follows... Sitename , spid1 12345678901234 1234567890 1234567 , spid2 1234567890 1234567890 1234567 Sitename , ... (1 Reply)
Discussion started by: drheams
1 Replies
Login or Register to Ask a Question