Operating System - HP-UX
1848488 Members
7416 Online
104029 Solutions
New Discussion

File manipulation Help ??

 
Praveen Hari
Advisor

File manipulation Help ??

#! rnews 0
Newsgroups: xxx
From: xxx
Subject: xxx
Date: xxx
Path: linux-nntp!forums-master!forums-1-dub!forums-1-dub!forums-master.sybase.com!forums-1-dub.sybase.com
Xref: linux-nntp sybase.test.xml:99
zzzzzzzzzzzzzzzzzzzzz

1)I need to replace "linux-nntp" in the line starting XRef: to "test".
2)I need to extract the number after sybase.text.xml from the line starting XRef: to a variable
3)Also I need to delete the text "linux-nntp!forums-master!" from the line starting "Path:"

Can soem one provide scripts for doing these operations.
Thanks
3 REPLIES 3
Hazem Mahmoud_3
Respected Contributor

Re: File manipulation Help ??

If you are willing to use perl, here is the code. This will definitely require tweaking, but I just put something simple down so you see what I'm doing. Let me know if you have any questions:

open (FILE, );

while() {

($garbage, $replace) = split(/:/);

if ($replace =~ "linux-nntp")
{
$replace =~ s/linux-nntp/test/;
($garbage2, $number) = split(/:/);
$var = $number;
}

($filename, $to_address) = split(/:/);

if ($replace =~ "linux-nntp!forums-master!")
{
$replace =~ s/linux-nntp!forums-master!//;
}


-Hazem
Hazem Mahmoud_3
Respected Contributor

Re: File manipulation Help ??

Oops, take out the last
($filename, $to_address) = split(/:/);

before the last if statement.

-Hazem
Jean-Luc Oudart
Honored Contributor

Re: File manipulation Help ??

Not sure what you want to do with the number
You may adapt from this script :

#!/bin/sh

awk '
{
if(substr($0,1,4)=="Xref") {
sub("linux-nntp","test");
split($0,tab,":");
num=tab[3];
}

if(substr($0,1,4)=="Path") {
sub("linux-nntp!forums-master!" ,"")
}
print $0;
}
END{print "NUMBER is",num;} ' $1

$1 is the file you want to process.
Regards,
Jean-Luc
fiat lux