![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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.. |
|
||||
|
Code:
sed -e 's/.*pmin=/s%Sieved to [0-9]*%Sieved to /;s/,factor.*/%/' checkpoint.txt | sed -f - otherfile The repetition of "Sieved to " can be avoided, but is left as an exercise. |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|