![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c program to extract text between two delimiters from some text file | kukretiabhi13 | High Level Programming | 7 | 12-03-2008 06:29 PM |
| Using awk to extract text | Davizzle | Shell Programming and Scripting | 5 | 08-15-2008 02:09 AM |
| how to extract columns from a text file | ihot | Shell Programming and Scripting | 16 | 05-06-2008 12:33 AM |
| To extract everything between two delimiters | dowsed4u8 | SUN Solaris | 1 | 01-16-2008 02:49 PM |
| How to extract text from xml file | chrisf | Shell Programming and Scripting | 3 | 09-01-2007 03:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
extract text b/w two delimiters
I have an input file which looks like
" @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql start $SCRIPT/art_matrix_audit_purge.pls start $SCRIPT/event_sku_price_log_purge.pls start $SCRIPT/event_sku_price_audit_purge.pls start $SCRIPT/event_sku_rscn_audit_purge.pls @$SCRIPT/in_process_audit_purge.sql $SCRIPT/dba2000.scr /NOLOG @$SCRIPT/mphdsum.pls ERROR_SCRIPT "Error with deduct.pls" $SCRIPT/dba2000.scr /NOLOG @$SCRIPT/pastdue.pls ERROR_SCRIPT "Error with pastdue.pls" $SCRIPT/dba2000.scr /NOLOG @$SCRIPT/ordpos1.pls ERROR_SCRIPT "Error with ordpos1.pls" $SCRIPT/dba2000.scr /NOLOG @$SCRIPT/ordpos2.pls ERROR_SCRIPT "Error with ordpos2.pls" ERROR_SCRIPT "Error Code:'$RCSUM!' in sum1so.sql" ERROR_SCRIPT "Error Code:'$RCSUM2' in sum2so.sql" ERROR_SCRIPT "Error Code:'$RCSUM3' in sum3so.sql" " My requirement is to extract all the text b/w : 1). "/" and ".sql" 2)."/" and ".pls" 3)." " and ".sql" 4)." " and ".pls" It is really urgent, any suggestion would be highly appreciated. Thanks NB: there might be a number of "/" in a line |
|
||||
|
You will need to do something more than just copy/paste as I am not going to write everything by you (you should learn it and code it), but here it goes:
1. You will fall into deep s**t whenever a filename contain special characters/new line. 2. Code: while read -p line; do [[ -z "${line}" ]] && continue line="${line##/|\ }" line="${line%.pls}" [[ -n "${line}" ]] && print -- "${line}" done EDIT: This is a korn shell's code to be clear. I believe that you could do it with one command using sed Last edited by adderek; 01-18-2008 at 06:25 AM.. Reason: Clarification |
|
||||
|
It is really tough to understand. Could you please explain me How didi you do that. I was applying a logic :
1). cut the line with the delimiter ".sql" and take the first field.(e.g spool $DATA/cim1021m) 2). convert all "/" to spaces and then (spool $DATA cim1021m) 3).delete everything till the last space(cim1021m) |
|
||||
|
If the input file is
" @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql " Then the output file must be " atp_asrmt_adj cim1005w cim1006w cim1020d cim1021m cim1021m cim1021m cim1021m cim1021m cim1021m " |
|
||||
|
You can do it using sed, awk and other.
The idea is to parse this line by line and to remove prefix and postfix. In ksh following syntax: line="${line#xxx}" is "remove trailing string "xxx" from the variable line. if not possible to remove then return me the string unmodified. then assign result to line". # : remove trailing part ## : remove trailing part (as much as possible) % : similar but for ending part %% : similar Example: x='aaabbb' "${x#a}" is 'aabbb' "${x##a}" is 'bbb' sed should handle this best (however I had some bad experience with lines longer than 255 chars in sed). Just tell him to remove replace {prefix_pattern}{?}{postfix_pattern} and replace it with {?}. Sory, but I don't remember exactly what was the syntax in sed. In example given by me you can see: line="${line##/|\ }" This is "remove prefix". And prefix is a pattern: '/' or ' ' line="${line%.pls}" This is "remove postfix". And postfix is '.pls'. Just replace this with a pattern and you have it. To pass the data for 'read -p' you could use cat file |& |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|