Sponsored Content
Top Forums Shell Programming and Scripting search pattern and replace x-y characters in nth line after every match Post 302537287 by neutronscott on Thursday 7th of July 2011 02:59:52 PM
Old 07-07-2011
This will work for a line, maybe more details will help me...

replace.sh:
Code:
#!/usr/bin/awk -f
FNR==1 { fnum++ }
/^HEADER$/ {h=1;l=0}
h {l++}
l==3 && fnum==1 { p1=$0; next }
l==3 && fnum==2 { print p1; next }
fnum==2 { print $0 }

Code:
[mute@geek ~/test]$ cat fileA
HEADER
some kinda of data aAAaaa
this is the new data aaAAAA
more data etc aaaa

[mute@geek ~/test]$ cat fileB
HEADER
some kinda of data in BBBB
this is the old data bbBBBb
more data etc bBBbBB

[mute@geek ~/test]$ ./replace.sh fileA fileB
HEADER
some kinda of data in BBBB
this is the new data aaAAAA
more data etc bBBbBB

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies

2. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies

3. Shell Programming and Scripting

Getting filename for Nth line pattern match

Hi, I have many scripts in particular directory. And few of the scripts have exit 0 in second line. Now i wanted to list out the scripts name which has the exit 0 in its second line I tried many options , but i can not get the filename along with the nth line pattern match :mad:. Can anyone... (14 Replies)
Discussion started by: puni
14 Replies

4. Shell Programming and Scripting

pattern match and replace another pattern in same line

I have a pattern username:x:32005:32006::/usr/local/user:/bin/bash I need to match the line containing username and replace /bin/bash with /usr/local/my/bin/noshell So it becomes username:x:32005:32006::/usr/local/user:/usr/local/my/bin/noshell (7 Replies)
Discussion started by: anilcliff
7 Replies

5. Shell Programming and Scripting

Help with replace line based on specific pattern match

Input file data20714 7327 7366 detail data20714 7327 7366 main data250821 56532 57634 detail data250821 57527 57634 main data250821 57359 57474 main data250821 57212 57301 main data250821 57140 57159 detail data250821 56834 57082 main data250821 56708 56779 main ... (3 Replies)
Discussion started by: perl_beginner
3 Replies

6. UNIX for Dummies Questions & Answers

Printing nth and n+1th line after a pattern match

Hi , I want to print the nth and n+1 lines from a file once it gets a pattern match. For eg: aaa bbb ccc ddd gh jjjj If I find a match for bbb then I need to print bbb as well as 3rd and 4th line from the match.. Please help..Is it possible to get a command using sed :) (6 Replies)
Discussion started by: saj
6 Replies

7. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

8. Shell Programming and Scripting

awk to search for specific line and replace nth column

I need to be able to search for a string in the first column and if that string exists than replace the nth column with "-9.99". AW12000012012 2.38 1.51 3.01 1.66 0.90 0.91 1.22 0.82 0.57 1.67 2.31 3.63 0.00 AW12000012013 1.52 0.90 1.20 1.34 1.21 0.67 ... (14 Replies)
Discussion started by: ncwxpanther
14 Replies

9. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

10. Shell Programming and Scripting

How to display when nth line match a pattern?

Hi All, I have sample of listing as following Database 2 entry: Database alias = PXRES Database name = PXRES Local database directory = /db2/data1/db2phnx Database release level = d.00 Comment ... (3 Replies)
Discussion started by: ckwan
3 Replies
Net::SIP::Packet(3pm)					User Contributed Perl Documentation				     Net::SIP::Packet(3pm)

NAME
Net::SIP::Packet - handling of SIP packets SYNOPSIS
use Net::SIP::Packet; my $pkt = eval { Net::SIP::Packet->new( $sip_string ) } or die "invalid SIP packet"; $pkt->get_header( 'call-id' ) || die "no call-id"; $pkt->set_header( via => @via ); print $pkt->as_string; DESCRIPTION
This module implements the parsing, manipulation and creation of SIP packets according to RFC3261. NET::SIP::Packet's objects can be created by parsing a string containing the SIP packet or by constructing it from parts, e.g. header keys and values, body, method+URI (requests) or code+text (responses). All parts can be manipulated and finally the string representation of the manipulated packet can be (re)created. For dealing with requests and responses directly usually the subclasses Net::SIP::Request or Net::SIP::Response will be used instead. EXAMPLES
# create packet from string my $invite = Net::SIP::Packet->new( <<'EOS' ); INVITE sip:you@example.com SIP/2.0 From: <sip:me@example.com> To: <sip:you@example.com> ... EOS # show and manipulate some header print "callid=".$invite->get_header( 'call-id' )." "; print "route=".join( ",", $invite->get_header( 'route' ))." "; $invite->set_header( 'via' => [ $via1,$via2,.. ] ); # get resulting string representation print $invite->as_string; # create packet from parts my $resp = Net::SIP::Packet->new( 200, 'Ok', { to => '<sip:you@example.com>', from => '<sip:me@example.com>',.. } Net::SIP::SDP->new(...) ); # and get the packet as string print $resp->as_string; CONSTRUCTOR
new ( STRING | @PARTS ) This is the default constructor. Depending on the number of arguments branches into new_from_string or new_from_parts. new_from_string ( STRING ) Interprets STRING as a SIP request or response and creates Net::SIP::Request or Net::SIP::Response object accordingly. Will die() if it cannot parse the string as a SIP packet. new_from_parts ( CODE|METHOD, TEXT|URI, \%HEADER|@HEADER, [ BODY ] ) If CODE|METHOD is numeric a Net::SIP::Response object will be created with the response code CODE and the text TEXT. Otherwise a Net::SIP::Request object will be created with the method METHOD and the uri URI. Header data can be given as a hash %HEADER or array @HEADER reference. In case of a hash the key is the SIP field name and the value as either a string or a @list of strings. The fields on the resulting SIP packet will be sorted by name of the fields and fields with multiple values will be created as seperat lines. If the header is given as an array the elements of the array are "[ key => value ]" pairs where the keys are the field names and the values are strings or @list of strings. Each pair will result in a single line in the SIP header. If the value was a list reference the values in the list will be concatened by ','. The order of the fields in the resulting SIP packet will be the same as in the array. The BODY is optional and can be given either as a string or as an reference to an object which has a method as_string, like Net::SIP::SDP. If the BODY is an object which has a method content_type it will set the "content-type" header of the SIP object based on the result of "BODY->content_type" unless a "content-type" header was explicitly given. METHODS
is_request Returns TRUE if the SIP packet is a request, otherwise FALSE. is_response Returns TRUE if the SIP packet is a response, otherwise FALSE. tid Returns a transaction ID created from the sequence number in the "CSeq" header and the "Call-Id" header. All packets with the same tid belong to the same transaction. cseq Returns "CSeq" header. Short for "$self->get_header( 'cseq' )". callid Returns "Call-Id" header. Short for "$self->get_header( 'call-id' )". get_header ( [ NAME ] ) If NAME is given it returns the SIP header for NAME. If no header exists returns (). If there is only one value for the header returns this value. In case of multiple values it returns a @list of all values, but if "wantarray" says, that the caller expects only a single value it will "croak()". If no NAME is given it will return a reference to a hash wich contains all fields and has the format described in new_from_parts. add_header ( NAME, VAL ) Adds the header at the end of the SIP header. VAL can be a string or a reference to a list of strings. insert_header ( NAME, VAL ) Like add_header, but the lines will be added on top of the header. del_header ( NAME ) Delete all lines from header where the field name is NAME. set_header ( NAME, VAL ) Replaces an existing header, like del_header followed by add_header. set_body ( VAL ) Sets body to VAL, which can be string or object. The handling for body objects see new_from_parts. as_string Returns string representation of SIP packet. dump ( [ LEVEL ] ) Returns dump of packet as string for debugging. The higher LEVEL is the more details one gets. At the moment a LEVEL of 0 gets a one- line summary and the rest the result from as_string. as_parts Returns Array with CODE|METHOD, TEXT|URI, @HEADER and BODY like used in new_from_parts. sdp_body Returns body as Net::SIP::SDP object if there is a body and the content-type is 'application/sdp' or empty. If body contains invalid SDP it raises an exception (e.g. die()). UNDOCUMENTED METHODS get_header_hashval ( [ NAME ] ) scan_header ( @ARG ) clone perl v5.14.2 2011-08-26 Net::SIP::Packet(3pm)
All times are GMT -4. The time now is 04:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy