extract text from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract text from a file
# 1  
Old 06-18-2010
extract text from a file

I have been reading several posts regarding how to extract text from a file, but none of those have helped me for what I need.
This is my problem: I need to extract the text after my pattern
So my line is:
485.74 6589.5 Log likelihood: 1485.79

My pattern is 'Log likelihood:'

and I need only the rest of the line: 1485.79

I can use "grep -w 'Log likelihood:' file" but get the whole line

How can I do it if i want only the beginning of the line: "485.74 6589.5" ?

Thanks guys
# 2  
Old 06-18-2010
To get only stuff after ":" try this:
Code:
echo "485.74 6589.5 Log likelihood: 1485.79" | cut -d":" -f2

or
Code:
echo "485.74 6589.5 Log likelihood: 1485.79" | awk -F: '{print $2}'

or
Code:
echo "485.74 6589.5 Log likelihood: 1485.79" | sed 's/.*://'



---------- Post updated at 00:54 ---------- Previous update was at 00:52 ----------

To get stuff before Log..., try this:
Code:
echo "485.74 6589.5 Log likelihood: 1485.79" | sed 's/Log.*//'



---------- Post updated at 00:55 ---------- Previous update was at 00:54 ----------

or
Code:
echo "485.74 6589.5 Log likelihood: 1485.79" | awk '{print $1" "$2}'

# 3  
Old 06-18-2010
Awesome!!

Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To extract query from a text file.

Hi, I've a txt file with the following contents: variable = "select name, emp_id, org_name " variable = variable + " from table_name where " variable = variable + " condition_1 = ABC and " variable = variable + " condition_2 = DEF " varaible = variable + " order by other condition " ... (7 Replies)
Discussion started by: arjun_arippa
7 Replies

2. Shell Programming and Scripting

Extract sentence and its details from a text file based on another file of sentences

Hi I have two text files. The first file is TEXTFILEONE.txt as given below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (7 Replies)
Discussion started by: my_Perl
7 Replies

3. Shell Programming and Scripting

extract a word from text file name

Hi i want to extract the word present before .txt in the text file. For example, Sample_ab_a.txt ----------> i need 'a' Sample_abc_b.txt -----------> i need 'b' Can anyone help me in getting the word extracted (5 Replies)
Discussion started by: Sindhuap
5 Replies

4. Shell Programming and Scripting

extract part of text file

I need to extract the following lines from this text and put it in different files. From xxxx@gmail.com Thu Jun 10 21:15:46 2010 Return-Path: <xxxxx@gmail.com> X-Original-To: xxx@localhost Delivered-To:xxxx@localhost Received: from ubuntu (localhost ) by ubuntu (Postfix) with ESMTP... (11 Replies)
Discussion started by: waxo
11 Replies

5. Shell Programming and Scripting

extract particular lines from text file

I have two files file A which have a number in every row and file B which contains few hundred thousand rows with about 300 characters in each row (csv) What I need is to extract whole rows from B file (only these which numbers are indicated in A file) I also need to use cygwin. Any... (7 Replies)
Discussion started by: gunio
7 Replies

6. UNIX for Dummies Questions & Answers

How to extract text from a line in file

I have a file abc.txt as below : <dbport oa_var="s_dbport" oa_type="EXT_PORT" base="1521" step="1" range="-1" label="Database Port">1616</dbport> <rpc_port oa_var="s_rpcport" oa_type="PORT" base="1626" step="1" range="-1" label="RPC Port">1721</rpc_port> <web_ssl_port oa_var="s_webssl_port"... (7 Replies)
Discussion started by: findprakash
7 Replies

7. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

8. Shell Programming and Scripting

how to extract columns from a text file

Hi, In ksh, I have a file with similar rows as follows: Department = 1234 G/L Asset Acct No = 12.0000. 2/29/2008 Department = 1234 G/L Asset Acct No = 13.0000. 3/29/2008. I want to create a new text file that contains only the numbers and date: 1234 12.0000. 2/29/2008 1234 13.0000. ... (16 Replies)
Discussion started by: ihot
16 Replies

9. Shell Programming and Scripting

How to extract text from xml file

I have some xml files that got created by exporting a website from RedDot. I would like to extract the cost, course number, description, and meeting information. <?xml version="1.0" encoding="UTF-16" standalone="yes" ?> - <PAG PAG0="3AE6FCFD86D34896A82FCA3B7B76FF90" PAG3="525312"... (3 Replies)
Discussion started by: chrisf
3 Replies

10. Shell Programming and Scripting

How to extract data from a text file

Hello All, Is there an easy way to extract data from a text file? The text file is actually a dump of a 2 page report with 6 columns and 122 lines. Example is Report Tile Type Product 1 Product 2 Product 3 Product 4... (1 Reply)
Discussion started by: negixx
1 Replies
Login or Register to Ask a Question