Sponsored Content
Top Forums Shell Programming and Scripting Replace first occurrence of a string in while loop Post 303034887 by RavinderSingh13 on Wednesday 8th of May 2019 09:45:27 PM
Old 05-08-2019
Hello baris35,

Very good that you have solved your question by yourself and appreciate that you have shared with us too, keep it up Smilie
You could better your solution by doing this:
Code:
awk '{sub("9030",$2+count++,$2)} 1'   Input_file

OR
Code:
awk '$2==9030{$2=$2+count++} 1'  Input_file

Output will be as follows.
Code:
aasasasas 9030 31wwo weopwoep
weerasas 9031 ew31wo ieopwoep
bbqqqsas 9032 ew3swo ieeopwoep
ccsaqpas 9033 ewiro o2opwoep

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search and replace to first occurrence of string

Hi all, I have a very large; delimited file. In vi I would like to replace: CSACT_DY;AVG_UEACT1;uesPerActiveLinkSetSize_1;#;A CSACT_DY;AVG_UEACT2;uesPerActiveLinkSetSize_2;#;A CSACT_DY;AVG_UEACT3;uesPerActiveLinkSetSize_3;#;A with: CSACT_DY;AVG_UEACT1;Average... (7 Replies)
Discussion started by: gilmord
7 Replies

2. Shell Programming and Scripting

Replace second occurrence only

HPUX /bin/sh (posix) I have a file as such cat dog mouse deer elk rabbit mouse rat pig I would like to replace the second occurrence of mouse in this file with mouse2. The rest of the file has to stay exactly as is. I'm not sure exactly where mouse might be (could be first,second,third... (5 Replies)
Discussion started by: lyoncc
5 Replies

3. Shell Programming and Scripting

SED replace string by occurrence

hi all, I have a text file with following content PAGENUMBER asasasa asasasa PAGENUMBER sasasasasa PAGENUMBER using sed i want to replace PAGENUMBER by occurrence count eg 1 asasasa asasasa 2 sasasasasa 3 (4 Replies)
Discussion started by: uttamhoode
4 Replies

4. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

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

6. Shell Programming and Scripting

Sed diffrent replace by occurrence

I couldn't find the answer anywhere, so I hope you could help me. I need to change something like the following: something/bla/aaaa anything/bbb to: something --bla ----aaaa anything --bbb How do I do this? Is it possible with sed? I tried various patterns, but don't know how to... (5 Replies)
Discussion started by: Patwan
5 Replies

7. UNIX for Dummies Questions & Answers

How to replace particular occurrence of character in between a delimiter?

Hi, Hi, I have a file with following format 1|" "text " around " |" fire "guest"|" " 2| "xyz"" | "no guest"|"3" 3| """ test3""| "one" guest"|"4" My requirement is to replace all occurrences of " to ' which are occurring between |" "|delimiter so my output should look like this 1|"... (3 Replies)
Discussion started by: H_bansal
3 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Replace first occurrence after match

hey guys, i have been trying to work this thing out with sed with no luck :confused: i m looking for a way to replace only the first occurrence after a match for example : Cat Realized what you gotta do Dog Realized what you gotta do Sheep Realized what you gotta do Wolf Realized... (6 Replies)
Discussion started by: boaz733
6 Replies

9. AIX

Replace consecutive occurrence of string in same line

Hi All, I have a requirement to replace consecutive occurence of same string nedd to be replaced. Below is the input and desired output. Input: --------- 123.5|ABC|.|.|. 234.4|DEF|.|.|.|.|.| Output: --------- 123.5|ABC|||. 234.4|DEF||||| so basically "|.|" need to be replaced with... (9 Replies)
Discussion started by: ureddy
9 Replies

10. Shell Programming and Scripting

Trim after nth occurrence with loop

Hello, Below command trims right after the nth occurrence of a string. When I try in while loop, it is not working. In Terminal IFS=/ ; read -ra val < Textfile ; echo "${val:0:3}" It gives only one line: sunday/monday/tuesday Textfile: sunday/monday/tuesday/wednesday/thursday... (2 Replies)
Discussion started by: baris35
2 Replies
MB_STRISTR(3)								 1							     MB_STRISTR(3)

mb_stristr - Finds first occurrence of a string within another, case insensitive

SYNOPSIS
string mb_stristr (string $haystack, string $needle, [bool $before_needle = false], [string $encoding = mb_internal_encoding()]) DESCRIPTION
mb_stristr(3) finds the first occurrence of $needle in $haystack and returns the portion of $haystack. Unlike mb_strstr(3), mb_stristr(3) is case-insensitive. If $needle is not found, it returns FALSE. PARAMETERS
o $haystack - The string from which to get the first occurrence of $needle o $needle - The string to find in $haystack o $before_needle - Determines which portion of $haystack this function returns. If set to TRUE, it returns all of $haystack from the beginning to the first occurrence of $needle (excluding needle). If set to FALSE, it returns all of $haystack from the first occurrence of $needle to the end (including needle). 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
stristr(3), strstr(3), mb_strstr(3). PHP Documentation Group MB_STRISTR(3)
All times are GMT -4. The time now is 03:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy