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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace 1st field leave all others alone

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all (reposting this). I have 4500+ files all close to being the same they're all 27 lines long. I'm trying to do an inplace edit for one variable but I can't seem to finesse it...

I have the following line inside every file

238 INVITE sip:$user@$server SIP/2.0\r

The number 238 is always changing and I need to remove those numbers altogether to leave:

INVITE sip:$user@$server SIP/2.0\r

Most of the changes I've made using awk, sed and perl (perl -pi -e 's/something/something else/g') but I can't find a way around this one... Remember the numbers change so in on instance it may be:

238 INVITE sip:$user@$server SIP/2.0\r

The next it may be:

1444 INVITE sip:$user@$server SIP/2.0\r

Any thoughts in this? Bear in mind, I will be passing $onevariable $twovariable (variables with $ signs). I tried to do it in one shot with awk and sed but it didn't work you would think sed 's/$/bar/g' would place bar at the end of each line but it did the opposite placed it in the beginning...

Here is one message:

2499 INVITE sip:<To> SIP/2.0
Via: SIP/2.0/UDP <From-Address>:<Local-Port>;branch=z9hG4bK000011
From: 11 <sip:<From>>;tag=11
To: Receiver <sip:<To>>
Call-ID: <Call-ID>@<From-Address>
CSeq: <CSeq> INVITE
Contact: 11 <sip:<From>>
Expires: 1200
Max-Forwards: 70
Content-Type: application/sdp
Content-Length: <Content-Length>

v=0
o=11 11 11 IN IP4 <From-Address>
s=Session SDP
c=IN IP4 <From-IP>
t=0 0
m=audio 9876 RTP/AVP 0
a=rtpmap:0 PCMU/8000
246 <Teardown-Method> sip:<To> SIP/2.0
Via: SIP/2.0/UDP <From-Address>:<Local-Port>;branch=z9hG4bK000011
From: 11 <sip:<From>>;tag=11
To: Receiver <sip:<To>>
Call-ID: <Call-ID>@<From-Address>
CSeq: <CSeq> <Teardown-Method>
Content-Length: 0

After I am done, it should be:
////

INVITE sip:$user@$server SIP/2.0
Via: SIP/2.0/UDP $remote:5060;branch=z9hG4bK000011
From: 11 <sip:$user@server>;tag=11
To: Receiver <sip:$user@server>
Call-ID: <$user@$server>
CSeq: $cseq INVITE
Contact: 11 <sip:$user@server>
Expires: 1200
Max-Forwards: 70
Content-Type: application/sdp
Content-Length: $random

v=0
o=11 11 11 IN IP4
s=Session SDP
c=IN IP4
t=0 0
m=audio 9876 RTP/AVP 0
a=rtpmap:0 PCMU/8000
246 ACK sip:$user@server
Via: SIP/2.0/UDP $server:$number;branch=z9hG4bK000011
From: 11 <sip:$user@server>;tag=11
To: Receiver <sip:$user@$server>
Call-ID: <$user@$server>
CSeq: $cseq INVITE
Content-Length: 0

////

No need to worry about $server $user $cseq those fields I've taken care of. This is nothing more than an example of what I need.... Reason for posting the entire text is because neither awk nor sed have worked for me... For edits on certain fields I've had success with perl (perl -pi -e 's/foo/bar/g') but I'm on a brainfart figuring out how to remove that 1st field...

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
something like this for starters:
Code:
sed 's#^\([0-9][0-9]*\) INVITE\(.*\)#INVITE\2#' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
or being politically correct:
Code:
nawk '$1 ~/^[0-9][0-9]*/ && $2 == "INVITE" {$1=""; sub(/^ */, "")}1' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top