Sponsored Content
Top Forums Shell Programming and Scripting Replace all string matches in file with unique random number Post 303024272 by apmcd47 on Friday 5th of October 2018 04:23:00 AM
Old 10-05-2018
Untested.
Code:
#!/bin/bash
rndm=($(shuf -e {00..99}))
while read line
do
   if [[ "$line" =~ ^Test ]]
   then
      printf "%s%s\n" Test ${rndm[10#${line#Test}]}
   else
      printf "%s\n" "$line"
   fi
done < infile > outfile

Creates a pseudo-random list of numbers 00-99 and uses the value of the current number in the test line to index the new number.

The 10# is required to stop bash from evaluating 08 and 09 as invalid octal numbers and instead evaluate them as valid decimals.

Andrew
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a certain string with string containing random rubbish

Hello, in my shell script i have some multi-line text in a variable $TEMP - f.e. blablahblah blah blah bla TARGET hgloglo And i need to replace TARGET with text from another variable ($REPLACE), which is containing some text with nasty characters (\n, ", :, etc.) And stuff the altered text... (2 Replies)
Discussion started by: MilanCZ
2 Replies

2. Shell Programming and Scripting

Replace a random string of numbers

Hi Can someone help me with this one? I have string.. (PROC_PROC_ID == 12183) <--PID is dynamic and i want to replace the PID number with whatever PID from /opt/hpws/apache32_2/logs/httpd.pid file. i'm having problem since the PID on the string is dynamic. It may be 2-5 digits or more. ... (5 Replies)
Discussion started by: ryandegreat25
5 Replies

3. UNIX for Dummies Questions & Answers

Sed to replace second number in a random string

I need a sed line that will take STDM111 and change it to STDM161 the STDM will always be constant but the 3 numbers after will be random, I just need it to always replace the middle number with 6 regardless of what the numbers are. (8 Replies)
Discussion started by: glev2005
8 Replies

4. Shell Programming and Scripting

Get line number when matches a string

If I have a file something like as shown below, ARM*187878*hjhj BAG*88778*jjjj COD*7777*kkkk BAG*87878*kjjhjk DEF*65656*89989*khjkk I need the line numbers to be added with a colon when it matches the string "BAG". Here in my case, I need something like ARM*187878*hjhj... (4 Replies)
Discussion started by: Muthuraj K
4 Replies

5. Shell Programming and Scripting

Using SED to replace a random number?

Hi all, I need to run a number of scripts which have a certain phrase on them so I have identified these by; grep -l 100 *script | sort -u Normally I could just run something along the lines of; for i in `grep -l 100 *script | sort -u`; do ./${i}; done However before I run each of... (0 Replies)
Discussion started by: JayC89
0 Replies

6. Shell Programming and Scripting

Replace 2nd column for each line in a csv file with fixed string+random number

Hi experts, My csv file looks like this U;cake;michael;temp;;;; U;bread;john;temp;;;; U;cocktails;sarah;temp;;;; I'd like to change the value fo 2nd column to cf+random number , which will look maybe something like this U;cf20187;michael;temp;;;; U;cf8926;john;temp;;;;... (7 Replies)
Discussion started by: tententen
7 Replies

7. Shell Programming and Scripting

Replace column by random number addition

Here is my problem:- I have a file with pipe separated values. CR|20121021|079|ABC|N|DLS|00038|DLS|04750|1330597704|634234|634|0 CR|20121021|079|ABC|N|DLS|00038|DLS|05118|2071690102|354|351|3 CR|20121021|079|ABC|N|DLS|00038|DLS|05140|960051505|1088|1088|0... (4 Replies)
Discussion started by: Yoda
4 Replies

8. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

9. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

10. UNIX for Beginners Questions & Answers

Replace matches string in each line with the arrayvalue in shell

I have a list of value , and need to replace that in my file. Eg: File1 tcname:fail tcname: Pass tcname:skipped File2: 01,02,03 Output: File 1 01:fail 02: Pass 03:Skipped (8 Replies)
Discussion started by: DevAakash
8 Replies
interceptors(3erl)					     Erlang Module Definition						interceptors(3erl)

NAME
interceptors - Describe the functions which must be exported by any supplied Orber native interceptor. DESCRIPTION
This module contains the mandatory functions for user supplied native interceptors and their intended behavior. See also the User's Guide. Warning: Using Interceptors may reduce the through-put significantly if the supplied interceptors invoke expensive operations. Hence, one should always supply interceptors which cause as little overhead as possible. Warning: It is possible to alter the Data , Bin and Args parameter for the in_reply and out_reply , in_reply_encoded , in_request_encoded , out_reply_encoded and out_request_encoded , in_request and out_request respectively. But, if it is done incorrectly, the consequences can be serious. Note: The Extra parameter is set to 'undefined' by Orber when calling the first interceptor and may be set to any Erlang term. If an interceptor change this parameter it will be passed on to the next interceptor in the list uninterpreted. Note: The Ref parameter is set to 'undefined' by Orber when calling new_in_connection or new_out_connection using the first interceptor. The user supplied interceptor may set NewRef to any Erlang term. If an interceptor change this parameter it will be passed on to the next intercep- tor in the list uninterpreted. EXPORTS
new_in_connection(Ref, PeerHost, PeerPort) -> NewRef new_in_connection(Ref, PeerHost, PeerPort, SocketHost, SocketPort) -> NewRef Types Ref = term() | undefined PeerHost = SocketHost = string(), e.g., "myHost@myServer" or "192.0.0.10" PeerPort = SocketPort = integer() NewRef = term() | {'EXIT', Reason} When a new connection is requested by a client side ORB this operation is invoked. If more than one interceptor is supplied, e.g., {native, ['myInterceptor1', 'myInterceptor2']} , the return value from 'myInterceptor1' is passed to 'myInterceptor2' as Ref . Ini- tially, Orber uses the atom 'undefined' as Ref parameter when calling the first interceptor. The return value from the last inter- ceptor, in the example above 'myInterceptor2', is passed to all other functions exported by the interceptors. Hence, the Ref parame- ter can, for example, be used as a unique identifier to mnesia or ets where information/restrictions for this connection is stored. The PeerHost and PeerPort variables supplied data of the client ORB which requested a new connection. SocketHost and SocketPort are the local interface and port the client connected to. If, for some reason, we do not allow the client ORB to connect simply invoke exit(Reason) . new_out_connection(Ref, PeerHost, PeerPort) -> NewRef new_out_connection(Ref, PeerHost, PeerPort, SocketHost, SocketPort) -> NewRef Types Ref = term() | undefined PeerHost = SocketHost = string(), e.g., "myHost@myServer" or "192.0.0.10" PeerPort = SocketPort = integer() NewRef = term() | {'EXIT', Reason} When a new connection is set up this function is invoked. Behaves just like new_in_connection ; the only difference is that the PeerHost and PeerPort variables identifies the target ORB's bootstrap data and SocketHost and SocketPort are the local interface and port the client ORB connected via. closed_in_connection(Ref) -> NewRef Types Ref = term() NewRef = term() When an existing connection is terminated this operation is invoked. The main purpose of this function is to make it possible for a user to clean up all data associated with the associated connection. The input parameter Ref is the return value from new_in_connection/3 . closed_out_connection(Ref) -> NewRef Types Ref = term() NewRef = term() When an existing connection is terminated this operation is invoked. The main purpose of this function is to make it possible for a user to clean up all data associated with the associated connection. The input parameter Ref is the return value from new_out_connection/3 . in_reply(Ref, Obj, Ctx, Op, Data, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Data = [Result, OutParameter1, ..., OutPramaterN] Reply = {NewData, NewExtra} When replies are delivered from the server side ORB to the client side ORB this operation is invoked. The Data parameter is a list in which the first element is the return value value from the target object and the rest is a all parameters defined as out or inout in the IDL-specification. in_reply_encoded(Ref, Obj, Ctx, Op, Bin, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Bin = #binary Reply = {NewBin, NewExtra} When replies are delivered from the server side ORB to the client side ORB this operation is invoked. The Bin parameter is the reply body still uncoded. in_request(Ref, Obj, Ctx, Op, Args, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Args = [Argument] - defined in the IDL-specification Reply = {NewArgs, NewExtra} When a new request arrives at the server side ORB this operation is invoked. in_request_encoded(Ref, Obj, Ctx, Op, Bin, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Bin = #binary Reply = {NewBin, NewExtra} When a new request arrives at the server side ORB this operation is invoked before decoding the request body. out_reply(Ref, Obj, Ctx, Op, Data, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Data = [Result, OutParameter1, ..., OutPramaterN] Reply = {NewData, NewExtra} After the target object have been invoked this operation is invoked with the result. The Data parameter is a list in which the first element is the return value value from the target object and the rest is a all parameters defined as out or inout in the IDL-speci- fication. out_reply_encoded(Ref, Obj, Ctx, Op, Bin, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Bin = #binary Reply = {NewBin, NewExtra} This operation is similar to out_reply ; the only difference is that the reply body have been encoded. out_request(Ref, Obj, Ctx, Op, Args, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Args = [Argument] - defined in the IDL-specification Reply = {NewArgs, NewExtra} Before a request is sent to the server side ORB, out_request is invoked. out_request_encoded(Ref, Obj, Ctx, Op, Bin, Extra) -> Reply Types Ref = term() Obj = #objref Ctx = [#'IOP_ServiceContext'{}] Op = atom() Bin = #binary Reply = {NewBin, NewExtra} This operation is similar to out_request ; the only difference is that the request body have been encoded. Ericsson AB orber 3.6.20 interceptors(3erl)
All times are GMT -4. The time now is 07:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy