Help required in writing the regular expression.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required in writing the regular expression.
# 1  
Old 04-28-2014
Linux Help required in writing the regular expression.

Code:
1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.617
Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.628
Task(0x5bac5060) tRestart (stack st: 0x5bace000, end:0x5bac8000) created
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.628
Task(0x219a4010) tShell0 (stack st:0x2242e000, end:0x2241a000) deleted
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.628
Task(0x219a4010) tShell0 (stack st: 0x2242e000, end:0x2241a000) created
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.628
Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.639
Task(0x5bac5060) tRestart (stack st: 0x5bace000, end:0x5bac8000) created
 1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.639

For the above lines I need to have the reqular expression for the line
1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.617
so that I get the below two lines
Code:
1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.617
Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted

Moderator's Comments:
Mod Comment Use code tags, please!
# 2  
Old 04-28-2014
Hello,

Following may help also.


Code:
awk '/^1 1982.*09:56:13.617$/ {getline; print $0}'  file_name

Output will be as follows.

Code:
Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 04-28-2014
Thanks Singh for the response.

But that is not what i need.

I need the two lines to be displayed.
1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.617 Task(0x5bac5060) tRestart (stack st:0x5bace000, end:0x5bac8000) deleted


Also the numbers in the first line can vary.

Moderator's Comments:
Mod Comment Removed accidental doublepost.
# 4  
Old 04-28-2014
So you just want to print all lines...?

What, exactly, do you not want to print?
# 5  
Old 04-28-2014
As i have explained earlier i need to get write the reqular expression for the first line so that it will read untill it encounters same line i.e., 1st line again.

I might have changed the requirement here.

For example : I have regular expression "^(?!Time).*$" which will read string starting with Time until it encounter the newline. Similar way i need regular expression for the line
" 1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.617 "
so that it will read until it encounters the next pattern which is similar to this.

Hope i have made the question clear. Let me know if not.
# 6  
Old 04-28-2014
Quote:
Originally Posted by VSSajjan
For example : I have regular expression "^(?!Time).*$" which will read string starting with Time until it encounter the newline. Similar way i need regular expression for the line
" 1 1982 1 testing init.cc 3001 Apr 25 2014 09:56:13.617 "
so that it will read until it encounters the next pattern which is similar to this.

Hope i have made the question clear. Let me know if not.
Emphasis mine.

Until which bits are similar -- How similar? How much difference is allowed? Be specific.
# 7  
Old 04-28-2014
similar to the line "
Code:
1 1982        1          testing            init.cc  3001     Apr 25 2014    09:56:13.617

"
Here the numbers and the strings might change
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why Relational Expression is Writing to a Expression?

Hello All, Not sure why this is happening... When the following If Statement is evaluated for some reason it is creating a file in the CWD called '0'. I've seen this happen before, just not in an If Statement... CODE: if then DIR_NAME="$1" DIR_SIZE=0 STATUS="" else... (3 Replies)
Discussion started by: mrm5102
3 Replies

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

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

4. Shell Programming and Scripting

Required help in perl regular expression substitution for this date format

Hi, I have written a small perl script to handle particular date format using perl, but it is not substituting the whole string. Can some one please check on what is the issue with the code. $_ = "Date: November 25, 2010 09:02:01 PM";... (1 Reply)
Discussion started by: sarbjit
1 Replies

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

6. Shell Programming and Scripting

Regular expression (regex) required

I want to block all special characters except alphanumerics.. and "."(dot ) character currently am using // I want to even block only single dot or multiple dots.. ex: . or .............. should be blocked. please provide me the reg ex. ---------- Post updated at 05:11 AM... (10 Replies)
Discussion started by: shams11
10 Replies

7. Shell Programming and Scripting

Help need in writing Regular Expression

Hi I need some help in writing a Regular expression. I am getting Date format like "Tue Apr 12 8:21:20 2009" I want to change the this format to "Tue Apr 12 2009 8:21:20" using regular expression Looking forward your help Thanks (6 Replies)
Discussion started by: TonySolarisAdmi
6 Replies

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

9. Shell Programming and Scripting

help required in writing the script

Hi All, Please help me in writting the script File contains: ========= 11424444, <basicpage> jfalfksf <dateofbirth>10/02/2005</dateofbrith> jkaklgja lg'd .... 11423224444, <basicpage> jfalfksf <dateofbirth>11/02/2005</dateofbrith> jkaklgja lg'd 11433523224444, <basicpage>... (4 Replies)
Discussion started by: thaduka
4 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