Sponsored Content
Full Discussion: Sed, last occurrence
Top Forums UNIX for Dummies Questions & Answers Sed, last occurrence Post 302848137 by xbin on Wednesday 28th of August 2013 02:18:45 PM
Old 08-28-2013
Code:
sed -n '/string/h;${x;p;}' file

Hold the last occurrence of the pattern "string"; put "string" into the pattern and print.
This User Gave Thanks to xbin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep for the same occurrence or maybe Sed

Hi, I have a file that looks like this dasdjasdjoasjdoasjdoa SYN dakspodkapsdka asdasdasdasdasdasdasd SYN sdfsdfsdfsdfdf shfishifhsdifhsidhfif fsdfsdfsdfsdfs sdfsdfsdfsdsdfsdfsdff cercercercerce sdasdajsdoajsodasodoo FIN dasdaskdpasdda... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

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

3. Shell Programming and Scripting

Using sed to substitute first occurrence

I am trying to get rid of some ending tags but I run into some problems. Ex. How are you?</EndTag><Begin>It is fine.</Begin><New> Just about I am trying to get rid of the ending tags, starts with </ and ending with >. (which is </EndTag> and </Begin>) I tried the following sed... (2 Replies)
Discussion started by: quixoticking11
2 Replies

4. Shell Programming and Scripting

Sed to print a string until the second occurrence of a character

Hi, I am totally new to shell scripting. I have a String "c:\working\html\index.txt.12-12-2009.bkp" I want to check if the string has more than one "." character. If it does I would like to retrieve only "c:\working\html\index.txt" i.e, discard the second occurrence of "." and the rest of the... (7 Replies)
Discussion started by: imr
7 Replies

5. Shell Programming and Scripting

SED to replace exact match, not first occurrence.

Lets say I have file.txt: (Product:Price:QuantityAvailable) (: as delimiter) Chocolate:5:5 Banana:33:3 I am doing a edit/update function. I want to change the Quantity Available, so I tried using the SED command to replace 5, but my Price which is also 5 is changed instead. (for the Banana... (13 Replies)
Discussion started by: andylbh
13 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

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

8. Shell Programming and Scripting

Modifying sed to only change last occurrence.

I'm using sed to switch integers (one or more digits) to the other side of the ':' colon. For example: "47593:23421" would then be "23421:47593". The way it functions right now, it is messing my settings file to use with gnuplot. The current command is: sed 's/\(*\):\(*\)/\2:\1/' out3 >... (3 Replies)
Discussion started by: D2K
3 Replies

9. UNIX for Dummies Questions & Answers

Substitution in first occurrence with sed

I have the following script: sed '/string1/,/string2/!d' infile I want to apply the script to the first occurrence only. I have tried sed '0,/string1/,/string2/!d' infile Of course, that does not work Any help will be greatly appreciated (12 Replies)
Discussion started by: Xterra
12 Replies

10. Shell Programming and Scripting

sed print from last occurrence match until the end of last occurrence match

Hi, i have file file.txt with data like: START 03:11:30 a 03:11:40 b END START 03:13:30 eee 03:13:35 fff END jjjjjjjjjjjjjjjjjjjjj START 03:14:30 eee 03:15:30 fff END ggggggggggg iiiiiiiiiiiiiiiiiiiiiiiii I want the below output START (13 Replies)
Discussion started by: Jyotshna
13 Replies
GRAPHEME_STRSTR(3)							 1							GRAPHEME_STRSTR(3)

grapheme_strstr - Returns part of haystack string from the first occurrence of needle to the end of haystack.

       Procedural style

SYNOPSIS
string grapheme_strstr (string $haystack, string $needle, [bool $before_needle = false]) DESCRIPTION
Returns part of haystack string from the first occurrence of needle to the end of haystack (including the needle). PARAMETERS
o $haystack - The input string. Must be valid UTF-8. o $needle - The string to look for. Must be valid UTF-8. o $before_needle - If TRUE, grapheme_strstr() returns the part of the haystack before the first occurrence of the needle (excluding the needle). RETURN VALUES
Returns the portion of string, or FALSE if needle is not found. EXAMPLES
Example #1 grapheme_strstr(3) example <?php $char_a_ring_nfd = "axCCx8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) normalization form "D" $char_o_diaeresis_nfd = "oxCCx88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) normalization form "D" print urlencode(grapheme_stristr( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_a_ring_nfd, $char_o_diaeresis_nfd)); ?> The above example will output: o%CC%88a%CC%8A SEE ALSO
grapheme_stristr(3), grapheme_stripos(3), grapheme_strpos(3), grapheme_strripos(3), grapheme_strrpos(3), Unicode Text Segmentation: Grapheme Cluster Boundaries . PHP Documentation Group GRAPHEME_STRSTR(3)
All times are GMT -4. The time now is 08:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy