Sponsored Content
Top Forums Shell Programming and Scripting Change only first line of the match Post 302881004 by bhas85 on Thursday 26th of December 2013 01:17:36 AM
Old 12-26-2013
Change only first line of the match

The below is the code which works correctly.But my requiremnt is to change only first line of the match i.e first match not whe file.

Code:
RAFTIP=rt950test.info53.com
RAFTPORT=21250
sed '5 c\
leprechaun.host.uri.list=raft' HostSocket.txt > tmp.properties
mv -f tmp.properties HostSocket.txt

LINE=`cat HostSocket.txt | grep ^leprechaun.host.uri.list=`
sed s!${LINE}!leprechaun.host.uri.list=raft://${RAFTIP}:${RAFTPORT}!g HostSocket.txt > tmp.properties
mv -f tmp.properties HostSocket.txt

file contians line like below
hostsocket.txt
Code:
leprechaun.2.uri.list=leprechaun2urilist
leprechaun.3.uri.list=leprechaun3urilist
leprechaun.4.uri.list=leprechaun4urilist
leprechaun.5.uri.list=leprechaun5urilist^
leprechaun.host.uri.list=raft://rt900test.info53.com:20025
leprechaun.1.uri.list=leprechaun1urilist
leprechaun.2.uri.list=leprechaun2urilist
leprechaun.8.uri.list=leprechaun8urilist
leprechaun.9.uri.list=leprechaun9urilist
leprechaun.host.uri.list=raft://11.1.120.154:20527,raft://10.1.182.2:21527
leprechaun.4.uri.list=leprechaun4urilist
leprechaun.5.uri.list=leprechaun5urilist
leprechaun.6.uri.list=leprechaun6urilist


OUTPUT SHUOLD BE AS FOLLOWS:
Code:
leprechaun.2.uri.list=leprechaun2urilist
leprechaun.3.uri.list=leprechaun3urilist
leprechaun.4.uri.list=leprechaun4urilist
leprechaun.5.uri.list=leprechaun5urilist
leprechaun.host.uri.list=raft://rt950test.info53.com:21250
leprechaun.1.uri.list=leprechaun1urilist
leprechaun.2.uri.list=leprechaun2urilist
leprechaun.3.uri.list=leprechaun3urilist
leprechaun.4.uri.list=leprechaun4urilist
leprechaun.5.uri.list=leprechaun5urilist
leprechaun.6.uri.list=leprechaun6urilist
leprechaun.7.uri.list=leprechaun7urilist
leprechaun.8.uri.list=leprechaun8urilist
leprechaun.9.uri.list=leprechaun9urilist
leprechaun.host.uri.list=raft://11.1.120.154:20527,raft://10.1.182.2:21527
leprechaun.4.uri.list=leprechaun4urilist
leprechaun.5.uri.list=leprechaun5urilist
leprechaun.6.uri.list=leprechaun6urilist

Please help me in this requiremnt.

Last edited by Don Cragun; 12-26-2013 at 03:50 AM.. Reason: Add CODE tags.
 

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

Script to change file contents line by line

Hi, I'm struggling to write a script to do the following, -will go through each line in the file -in a specific character positions, changes the value to a new value -These character positions are fixed througout the file ----------------------- e.g.: file1.sh will have the following 3... (4 Replies)
Discussion started by: vini99
4 Replies

3. Shell Programming and Scripting

Print Line if next line Match a pattern

Hi All, Does anyone know how to print 1H1A....... in peal script print line ^1H1A....... if next line equal 5R0RECEIPT.... Thank for help:D Cat st.txt 1H1A-IN-11-5410-0009420|1010047766|dsds|1|N|IN|IN|000000|1||N|<<<line match 5R0RECEIPT| 5R0RECEIPT|... (2 Replies)
Discussion started by: kittiwas
2 Replies

4. Shell Programming and Scripting

Delete line with match and previous line quoting/escaping problem

Hi folks, I've list of LDAP records in this format: cat cmmac.export.tmp2 dn: deviceId=0a92746a54tbmd34b05758900131136a506,ou=devices,ou=customer,ou=nl,o=upc cmmac: 00:13:11:36:a5:06 dn: deviceId=0a92746a62pbms4662299650015961cfa23,ou=devices,ou=customer,ou=nl,o=upc cmmac:... (4 Replies)
Discussion started by: tomas.polak
4 Replies

5. Shell Programming and Scripting

awk or sed? change field conditional on key match

Hi. I'd appreciate if I can get some direction in this issue to get me going. Datafile1: -About 4000 records, I have to update field#4 in selected records based on a match in the key field (Field#1). -Field #1 is the key field (servername) . # of Fields may vary # comment server1 bbb ccc... (2 Replies)
Discussion started by: RascalHoudi
2 Replies

6. 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

7. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

8. 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

9. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

10. Shell Programming and Scripting

Print next line beside preceding line on column match

Hi, I have some data like below: John 254 Chris 254 Matt 123 Abe 123 Raj 487 Moh 487 How can i print it using awk to have: 254 John,Chris 123 Matt,Abe 487 Raj,Moh Thanks. (4 Replies)
Discussion started by: james2009
4 Replies
URI::ldap(3)						User Contributed Perl Documentation					      URI::ldap(3)

NAME
URI::ldap - LDAP Uniform Resource Locators SYNOPSIS
use URI; $uri = URI->new("ldap:$uri_string"); $dn = $uri->dn; $filter = $uri->filter; @attr = $uri->attributes; $scope = $uri->scope; %extn = $uri->extensions; $uri = URI->new("ldap:"); # start empty $uri->host("ldap.itd.umich.edu"); $uri->dn("o=University of Michigan,c=US"); $uri->attributes(qw(postalAddress)); $uri->scope('sub'); $uri->filter('(cn=Babs Jensen)'); print $uri->as_string," "; DESCRIPTION
"URI::ldap" provides an interface to parse an LDAP URI into its constituent parts and also to build a URI as described in RFC 2255. METHODS
"URI::ldap" supports all the generic and server methods defined by URI, plus the following. Each of the following methods can be used to set or get the value in the URI. The values are passed in unescaped form. None of these return undefined values, but elements without a default can be empty. If arguments are given, then a new value is set for the given part of the URI. $uri->dn( [$new_dn] ) Sets or gets the Distinguished Name part of the URI. The DN identifies the base object of the LDAP search. $uri->attributes( [@new_attrs] ) Sets or gets the list of attribute names which are returned by the search. $uri->scope( [$new_scope] ) Sets or gets the scope to be used by the search. The value can be one of "base", "one" or "sub". If none is given in the URI then the return value defaults to "base". $uri->_scope( [$new_scope] ) Same as scope(), but does not default to anything. $uri->filter( [$new_filter] ) Sets or gets the filter to be used by the search. If none is given in the URI then the return value defaults to "(objectClass=*)". $uri->_filter( [$new_filter] ) Same as filter(), but does not default to anything. $uri->extensions( [$etype => $evalue,...] ) Sets or gets the extensions used for the search. The list passed should be in the form etype1 => evalue1, etype2 => evalue2,... This is also the form of list that is returned. SEE ALSO
<http://tools.ietf.org/html/rfc2255> AUTHOR
Graham Barr <gbarr@pobox.com> Slightly modified by Gisle Aas to fit into the URI distribution. COPYRIGHT
Copyright (c) 1998 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2012-02-11 URI::ldap(3)
All times are GMT -4. The time now is 03:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy