Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to remove some unwanted info in the file using sed? how to do ? 3

Status
Not open for further replies.

CALYAN

Programmer
Apr 23, 2001
39
US
Actually I used awk program and extracted the second col
of data file, it extracted data with some numeric conts
how to remove this using sed?

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

00219 PNL04/601784

 
do you want only the lines with numbers in them?

you could use awk to do that as well in the same operation.

what awk command did you use to create the list, and what output do you want?
 
I have a similar issue. However, I am trying to remove a Control Character. How can I remove it?

I was typing: cat file1 | sed 's/\^V\^M//g' > file2
where '^M' is the control character I want to remove.

Any thoughts?
 
Try this - you don't need cat :-
sed 's/'"$(printf '\013')"'$// s/'"$(printf '\022')"'$//' filein > fileout
Assumes 013 is ^M and 022 is ^V ( I haven't checked this )

Dickie Bird (:)-)))
 
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

BEY
BEY
BEY
BEY
BEY
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?
 
If you want to remove records where $2 is starting with a numeric character :

gzcat Jan05.gz | awk 'BEGIN { FS = "|" } ; $2 !~ /^[0-9]/ { print $2 }' > cnt

Jean Pierre.
 
Hi Jean,

Thanks, and also i want to remove blank spaces and the characters more than 3.
example

BEY
BEY
BEY

RM10 7XS

BEY

thanks in advacne

kalyan
 
This will print $2 only when it is 3 uppercase letters...

awk 'BEGIN { FS = "|" } ; $2 ~ /^[A-Z]{3}$/ { print $2 }'
 
Try this, and adapt if necessary :

[tt]
gzcat Jan05.gz | awk '
BEGIN {
FS = "|"
}
{
gsub(" ","",$2); # remove spaces
$2 = substr($2,1,3); # trunc to 3 characters
if ($2 ~ "^([0-9]|$)") # if empty or starting whith numeric char
next # ignore
print $2;
}' > cnt
[/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top