advanced regular expression?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting advanced regular expression?
# 1  
Old 03-18-2010
advanced regular expression?

Hello,
I've got to filter some text from a file, where one line looks like this:

29118 open("/lib64/libtinfo.so.5", O_RDONLY) = 3

It's an output from strace as you probably understand and I want to filter from it the path of the opened program, that means

/lib64/libtinfo.so.5

There's no problem to do it for example with sed, but the problem comes when there will be some opened file called

/usr/file"with"quotation"marks

Don't know how to solve it properly with some advanced regexp.
Do you have any strong ideas?
Thank you for answers!
# 2  
Old 03-18-2010
don't quite understand the issue, but:
Code:
echo '29118 open("/lib64/libtinfo.so.5", O_RDONLY) = 3' |sed '/ open/s/.*"\([^"][^"]*\)".*/\1/'

# 3  
Old 03-18-2010
thank you for an idea, but your solution only works when the filename is normal.. but i have to solve all the situations, that means when a user is some bfu and names some textfile for example "ha"ha"ha", then i have to filter it like "ha"ha"ha" .. This is the thing that i can't write some strong regexp, which would be able to read the path and name of the file even if there are quotation marks in there.
# 4  
Old 03-18-2010
Can you provide a couple of the different examples, pls (in the same strace format)?
# 5  
Old 03-18-2010
29118 open("/lib64/libc.so.6", O_RDONLY) = 3
29120 open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) =3
29119 open("/proc/mounts", O_RDONLY) = 3
29121 open("/usr/bin/my"program", O_RDONLY) = 3

the output should be

/lib64/libc.so.6
/usr/share/locale/en/LC_MESSAGES/coreutils.mo
/proc/mounts
/usr/bin/my"program

but using your code, or mine it fails on the last line (and that's what's this thing all about), because on the last line of the output it writes only

program
# 6  
Old 03-18-2010
Code:
sed '/ open/s/[^"]*"\([^,][^,]*\)",.*/\1/' myFile

unless of course you have ',' embedded in the file name as well.

Or more generically:
Code:
sed '/ open/s/[^"]*"\(.*\)",.*/\1/' myFile

myFile:
Code:
29118 open("/lib64/libc.so.6", O_RDONLY) = 3
29120 open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) =3
29119 open("/proc/mounts", O_RDONLY) = 3
29121 open("/usr/bin/my"program", O_RDONLY) = 3
29121 open("/usr/bin/my,program", O_RDONLY) = 3
29121 open("/usr/bin/my",program", O_RDONLY) = 3


Last edited by vgersh99; 03-18-2010 at 05:25 PM..
# 7  
Old 03-18-2010
Thank you very much, it seems that this regexp solved it Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Regular expression

Hi I need to write a regular expression for a language. That language can have {a, b, c} as alphabet and it must contain minimum one "a" and minimum one "b". Can u help me to write it plz! thanks in advance! (1 Reply)
Discussion started by: nishrestha
1 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

regular expression

Could anyone of you please guide me on making correct regular expression to match the exact word or character I have some numbers like 12345780 extn 1234 1234567 x 43545 13245678 Extn 454857 if * ]]; then VAR3=`echo "$NUMBER" | nawk -F "*" '{print $1 $2}'` ... (4 Replies)
Discussion started by: nram_krishna@ya
4 Replies

5. Programming

Need Regular expression

Need regular expression to accept alphabets or numbers for first three places (1 Reply)
Discussion started by: dineshmurs
1 Replies

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

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

8. Programming

What does the regular expression ['(^[^~]+~).*'] mean?

What does the regular expression +~).*'] mean while using it with regexec.When the string "RCHNUSNT35C~rs07/ASM-RS07" is used with the regular expression +~).*'] regexec gives an error. I know what regexec does,but i do not understand what this expression means wrt to this string... any help... (2 Replies)
Discussion started by: anupamar
2 Replies

9. UNIX for Dummies Questions & Answers

Need help in Regular Expression

I have a file with data that looks like - record nullable { final_delim=end ,delim="~%%~" ,quote=none } ( 1_UPC:string; 2_QUANTITY:string; ) I want to fetch the first column that starts with integer. e.g - 1_UPC, 2_QUANTITY. I tried "awk -F ":" -v var1="^0-9" '$1==var1' inschemafile".... (2 Replies)
Discussion started by: mahabunta
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