Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Sed to replace second number in a random string Post 302383174 by Franklin52 on Monday 28th of December 2009 04:51:38 PM
Old 12-28-2009
Quote:
Originally Posted by glev2005
Franklin, it seems to mostly work, could you please explain it a little?
Explanation:
Code:
sed 's/\(.*STDM.\).\(.*\)/\16\2/'

With sed you can save substrings with \(.*\) and recall them back with \1, \2, \3 etc.

\(.*STDM.\).\(.*\)

The 1st portion \(.*STDM.\) is from the start of the line till the character after STDM (hence the dot)
The 2st portion .\(.*\) is from one character after the 1st portion (hence the dot before the substring) till the end of the line

\16\2

\1 -> print the 1st portion
6 -> print a "6"
\2 -> print the 2nd portion
 

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

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

3. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

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

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 x Number of String Occurrence with Sed

Ok, So I have a huge file that has over 12000 lines in it. in this file, there are 589 occurrences of the string "use five-minute-interval" spread in various areas in the file. How can i replace the the last 250 of the occurrences of "use five-minute-interval" with "use... (10 Replies)
Discussion started by: SkySmart
10 Replies

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

8. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

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

10. Shell Programming and Scripting

Replace all string matches in file with unique random number

Hello Take this file... Test01 Ref test Version 01 Test02 Ref test Version 02 Test66 Ref test Version 66 Test99 Ref test Version 99 I want to substitute every occurrence of Test{2} with a unique random number, so for example, if I was using sed, substitution would be something... (1 Reply)
Discussion started by: funkman
1 Replies
MB_STRRICHR(3)								 1							    MB_STRRICHR(3)

mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive

SYNOPSIS
string mb_strrichr (string $haystack, string $needle, [bool $part = false], [string $encoding = mb_internal_encoding()]) DESCRIPTION
mb_strrichr(3) finds the last occurrence of $needle in $haystack and returns the portion of $haystack. Unlike mb_strrchr(3), mb_strrichr(3) is case-insensitive. If $needle is not found, it returns FALSE. PARAMETERS
o $haystack - The string from which to get the last occurrence of $needle o $needle - The string to find in $haystack o $part - Determines which portion of $haystack this function returns. If set to TRUE, it returns all of $haystack from the beginning to the last occurrence of $needle. If set to FALSE, it returns all of $haystack from the last occurrence of $needle to the end, o $encoding - Character encoding name to use. If it is omitted, internal character encoding is used. RETURN VALUES
Returns the portion of $haystack. or FALSE if $needle is not found. SEE ALSO
mb_stristr(3), mb_strrchr(3). PHP Documentation Group MB_STRRICHR(3)
All times are GMT -4. The time now is 01:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy