LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-23-2010, 12:23 PM   #16
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

Original Poster
Rep: Reputation: 15

crts--I just tried that and wrote in test2:
105
46

You can see where those numbers came from if you look back at the line. Interesting result. Thank you all for staying with me. I really appreciate it.
 
Old 08-23-2010, 12:26 PM   #17
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by Feynman View Post
crts--I just tried that and wrote in test2:
105
46

You can see where those numbers came from if you look back at the line. Interesting result. Thank you all for staying with me. I really appreciate it.
Try
Code:
sed -nr "s/.*${pattern}[      ]*([^     ]+).*/\1/p" /opt/gamess/tests/exam12.inp > test2
The problem is that \w will get a whole word. The '.' is considered a word boundary and therefor not part of the result. Since you want 46.xxx as result \w is not suitable. This was not obvious from your first post. That is why you should always provide sample data as accurate as possible.

P.S.: If you can be certain that there are no tabs in your file you can omit the tab characters and use only spaces inside [] instead of both.

Last edited by crts; 08-23-2010 at 12:32 PM.
 
1 members found this post helpful.
Old 08-23-2010, 12:40 PM   #18
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

Original Poster
Rep: Reputation: 15
crts--when I tried your script test2 read
105
46

You can see where these numbers came from if you look at the line I am extracting from. Weird result.
Thanks for staying with me.
 
Old 08-23-2010, 12:42 PM   #19
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

Original Poster
Rep: Reputation: 15
sorry ignore that last post. I did not notice the "next page feature"
 
Old 08-23-2010, 12:45 PM   #20
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

Original Poster
Rep: Reputation: 15
Sorry, I will try to be clearer. Now I got
105.14088
46.45648

How do I just get the first number?
 
Old 08-23-2010, 12:57 PM   #21
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
???

Quote:
Originally Posted by Feynman View Post
Sorry, I will try to be clearer. Now I got
105.14088
46.45648

How do I just get the first number?
Based on your sample data
Code:
I tried typing the input by the forum seems to automatically take out extra spaces (obviously ctrs found a way around that). Here is what the particular line would look like:
![3 spaces]Heat OF FORMATION[9 spaces]105.14088[3 spaces]93.45997[3 spaces]46.89387
you already got the first number. The number 46.45648 is from another line. It is not 46.89387 form the same line. Notice, that they are not equal. If you do not want to process anymore lines after the first match then try
Code:
sed -nr "/${pattern}/ {s/.*${pattern}[      ]*([^     ]+).*/\1/p;q}" /opt/gamess/tests/exam12.inp > test2
Maybe it is best if you post your data file as attachment and tell us what data you want extracted.
 
1 members found this post helpful.
Old 08-23-2010, 01:06 PM   #22
Feynman
Member
 
Registered: Aug 2010
Distribution: Gentoo
Posts: 62

Original Poster
Rep: Reputation: 15
That worked great! Thank you very much! I wanted to attach my data but could not figure out how. Next time!
 
Old 08-23-2010, 01:28 PM   #23
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by Feynman View Post
That worked great! Thank you very much! I wanted to attach my data but could not figure out how. Next time!
When you reply (not quick reply) look out for the "paper-clip" symbol. Keep in mind that attaching is "extension" sensitive. You will have to rename the file like

filename.txt

Otherwise you won't be able to upload it.
 
Old 08-24-2010, 03:00 AM   #24
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by crts View Post
@konsolebox: I am also not quite sure what you mean. Since sed uses the -r switch for extended regex there should be no need to escape the braces.
When has sed implement -r of super sed... I never thought about it.
 
Old 08-24-2010, 12:27 PM   #25
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,964
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Quote:
Originally Posted by konsolebox View Post
When has sed implement -r of super sed... I never thought about it.
Not sure when exactly it got introduced, but I have
an inkling it was around the version jump from 3.xx -> 4.xx

I've certainly been using it for a long time.



Cheers,
Tink
 
  


Reply

Tags
extract, parse, string, text, word


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
grep string with space (2 word string) casperdaghost Linux - Newbie 7 08-24-2009 02:11 AM
extract text only from ms word in php sriphp Linux - Newbie 2 05-11-2009 01:07 AM
variable length string using GD (word wrap, carriage return, word/character count)? frieza Programming 1 02-14-2009 05:21 PM
How to extract Data from word document? nesta Programming 3 11-26-2008 11:35 AM
scripting question: Extract a particular word from /proc/cmdline kushalkoolwal Programming 3 05-14-2008 02:48 AM


All times are GMT -5. The time now is 12:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration