If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > i want to remove the patterns like this how to do?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-06-04, 05:23
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
i want to remove the patterns like this how to do?

example of data file

BEY
BEY
BEY
BEY
BEY
BEY
00219 ELC03/306739 (i want to remove the patterns like this how to do)

00219 IC03/502508

00219 (TBI)

00219 PNL04/601784

TEB
TEB
TEB
TEB
TEB
TEB
Reply With Quote
  #2 (permalink)  
Old 01-06-04, 08:19
chillies chillies is offline
Registered User
 
Join Date: Jul 2003
Location: Edinburgh
Posts: 35
It depends what you want to do ...

If that string only occurs once, you could fire up an editor and remove the line.

Both
grep -v '00219 ELC03/306739' <insert filename here>
and
sed '/00219 ELC03\/306739/d' <insert filename here>
(notice the backslash) will output the contents of the data file with all lines which contain the string "00219 ELC03/306739" removed. You'll need to do more processing if you want the string removed from the original file.
Reply With Quote
  #3 (permalink)  
Old 01-06-04, 20:56
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
Re: i want to remove the patterns like this how to do?

Hi My data file islike this

7777777711|SIN|ESC|SIN||2003-09-08 11:00:00|D|FOCMATHUB|FOCMATHUB|DHL/SIN HUB OF
FICE|819458|TEST||TEST DATA|TEST DATA|TEST DATA|TEST DATA|TEST DATA|SINGAPORE|EX
PRESS DOCUMENT|DOX||TEST|75 AIRPORT CARGO ROAD|SINGAPORE|||||||||TEST DATA||||SI
NGAPORE||SG|
I used
gzcat Jan05.gz | awk 'BEGIN { FS = "|" } ; { print $2 }' > cnt to extract the second column

I need only

SIN
BEY
SIN
BEY
BEY
BEY

But my file cnt contains

BEY
BEY
BEY
BEY
00219 ELC03/306739
00219 IC03/502508
00219 (TBI)
BEY
BEY
BEY

I want to remove the 00219 ELC03/306739
00219 IC03/502508
00219 (TBI) contents how to do it? i WANT TO DO IT
AN GENERIC MANNER AND NOT PARTICULARY THIS TEXT ANY NUMBER OR CHARS MORE THAT 3 I WANT TO REMOVE IT HOW TO DO?
Reply With Quote
  #4 (permalink)  
Old 01-06-04, 21:22
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
The tool that comes to my mind with tasks like this is 'Awk.' I don't know exactly what the acronym stands-for but it's really useful for working with complex inputs a line at a time. For example, it's handy when all you've got is the output of a COBOL report (saved to a disk file) and you're supposed to extract some data from it.

Another tool might be 'grep' (global regular expression pooh-bah).

A surprisingly useful programming language for working with files like this is also, Python. If you can use Perl then be my guest. ;-)
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
  #5 (permalink)  
Old 01-07-04, 03:46
calyan calyan is offline
Registered User
 
Join Date: Jan 2004
Posts: 28
I used awk and extracted the data file and i want to remove the numeric
contents that can done with sed . I dont know how to do it in generic
maaner. please tell me.

awk - The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan AWK

ok----

regards
s.kalyan
Reply With Quote
  #6 (permalink)  
Old 01-07-04, 03:57
chillies chillies is offline
Registered User
 
Join Date: Jul 2003
Location: Edinburgh
Posts: 35
Re: i want to remove the patterns like this how to do?

The pattern match selects fields of length exactly three characters:

awk 'BEGIN{FS="|";} $2 ~ /^...$/ { print $2; }'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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