The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need to search text and output previous lines grinds Shell Programming and Scripting 8 05-07-2008 09:31 AM
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 06:08 AM
execl() + redirecting output to text files JamesGoh High Level Programming 5 02-18-2008 05:17 PM
Searching and extracting text from output sjday Shell Programming and Scripting 3 12-07-2007 04:12 AM
Extract text in 2 columns of output file. Danish Shakil Shell Programming and Scripting 2 10-19-2007 10:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-28-2008
raffi raffi is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
output text in between

how can i output the number 2641569270623 from a text file called checkpoint.txt that is a one line file (generated by a maths sieving program) that looks like:
pmin=2641569270623,factor_count=8,cpu_secs=1705.793,frac_done=0.002592,elapsed_secs=1710.844

i tried sed -n "/pmin=/,/,factor/ p" checkpoint.txt | sed "$ d" which ouputs nothing and sed -n "/pmin=/,/,factor/ p" checkpoint.txt which output the whole line
  #2 (permalink)  
Old 04-28-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Try this:

Code:
sed '/^pmin=/s/pmin=\([^,]*\),.*/\1/' file
Regards
  #3 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Ranges in sed are ranges of entire lines -- /pmin=/,/,factor/ means print each line starting with a line containing "pmin=" through a different line containing ",factor" (and starting over again if a subsequent line matches "pmin=" again).

You could do

Code:
sed -e 's/.*pmin=//;s/,factor.*//' checkpoint.txt
which will replace from start of line through "pmin=" with empty line, and ditto from ",factor" through to end of line. The result is still printed regardless of whether the resulting line is empty or not.
  #4 (permalink)  
Old 04-28-2008
raffi raffi is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
both arguments work PERFECTLY. thanks alot guys!
  #5 (permalink)  
Old 04-28-2008
raffi raffi is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
is it possible to use this output to replace text from another file in one command?

ie: replace the "720" in line 1 of a different file with text comtaining "Sieved to 720" with the 2641569270623 we extracted from the original file?

Last edited by raffi; 04-28-2008 at 06:48 PM..
  #6 (permalink)  
Old 04-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
sed -e 's/.*pmin=/s%Sieved to [0-9]*%Sieved to /;s/,factor.*/%/' checkpoint.txt |
sed -f - otherfile
If your sed won't do "-f -" you will have to save to a temporary file.

The repetition of "Sieved to " can be avoided, but is left as an exercise.
  #7 (permalink)  
Old 04-29-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
You can also include the whole sed command within the sed command and pipe it to sh:

Code:
sed '/^pmin=/s/pmin=\([^,]*\),.*/sed '"'"'s%Sieved to [0-9]*%Sieved to \1%'"'"' other_file/' file | sh
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0