Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/lrpg/documentation/procedures/lrpg_using_sed.html
Дата изменения: Tue Jun 3 23:20:29 2003
Дата индексирования: Sun Mar 2 09:14:30 2014
Кодировка:

Поисковые слова: п п п п

Using sed in the LRPG

This document is a brief tutorial on how to use unix's sed, "stream editor" to manipulate an output list to construct a list of commands to perform on each of the visits. The example outlined below takes the output from "expire_list" which has been copied into a unix file and then uses sed to extract the sunit_ids and construct plan-window-copy commands which can be placed into a VMS com-file for batch execution.

Sed's command line syntax essentially means this:

sed 's/search_for_this/replace_with_this/' file_name_to_operate_on

Let us examine a sed command breaking it up into components to see what the individual pieces do:

sed 's/^\(.......\).*$/$do copy_visit_into_lrp 98259A 98259X \1/' ~jordan/98285


sed

's/

^

\(

.......

\)

.*

$

/

$

do copy_visit_into_lrp 98295A 98259X

\1

/'

~jordan/file98285


Examples:

  • sed 's/^\(.......\).*$/$do copy_visit_into_lrp 98259A 98259X \1/' ~jordan/98285

    Take the first 7 characters (sunit_id) from the input file ~jordan/98285 and process them into a list of VMS LRPG commands which copy them from one LRP to another.

  • egrep -i "Severity E" batch_log.thu | sed 's/.*\([0-9][0-9][0-9][0-9]\).*/\1c/' | sort -u

    A combination command which 'greps' a batch_log file for a string containing a 4-digit proposal_id (which it grabs and stores), and then pipes it to sed so that it can grab the proposal ids and output them uniquely in a format that is compatible with find_lrp.lis input to a SPIKE run.

  • sed -f ~jordan/sed_script nonmama_didnt_schedule

    Use of a file ~jordan/sed_script to store a sed script which is difficult to do from a command line. The script file ~jordan/sed_script contains:

    Note that this script outputs multiple lines instead of just one line for each input record.

    More examples (uncommented) on using sed with data in files (often in conjunction with other tools):

    
    head -1 /home/lrp/current_available_list.rpt | sed 's/.*LRP= \(.*\)/\1/'
    
    cut -c1-7 t1204_g.available_c12_sort4 | egrep -v 9803 | sed 's/\(.......\)/(delete-pw "\1")/' > delpw
    
    cut -c2-15 alrp | sed 's/\(.*\)/archive-lrps name=\1/' > archem