The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-18-2008
dowsed4u8 dowsed4u8 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 6
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
  #2 (permalink)  
Old 01-18-2008
adderek adderek is offline
Registered User
  
 

Join Date: Sep 2007
Location: Poland
Posts: 111
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
  #3 (permalink)  
Old 01-18-2008
dowsed4u8 dowsed4u8 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 6
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)
  #4 (permalink)  
Old 01-18-2008
dowsed4u8 dowsed4u8 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 6
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

"
  #5 (permalink)  
Old 01-18-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
Code:
awk 'BEGIN{ FS="[/ ]"}{print $NF} ' file
  #6 (permalink)  
Old 01-18-2008
adderek adderek is offline
Registered User
  
 

Join Date: Sep 2007
Location: Poland
Posts: 111
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 |&
  #7 (permalink)  
Old 01-18-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,932
If you provide an example of the output you expect, somebody may be able to help you.
Closed Thread

Bookmarks

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 08:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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