Sponsored Content
Top Forums Shell Programming and Scripting Help search and replace the last occurance of match in a file Post 303012392 by jim mcnamara on Saturday 3rd of February 2018 09:14:48 AM
Old 02-03-2018
Code:
# expanded lines and fixed errors
awk '{ arr[NR]=$0; 
       if (index($0,"union all")>0)  
       {L=NR} 
     }
END { 
      gsub(/union all/, "", arr[L])
      for(i=0; i<NR; i++) 
             {print arr[i] }
    }'  infile > outfile

This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

replace the n'th occurance in a file

Hi All, How can i replace the n'th occurance in a file. ? I have a property file like EAR;_TrackingEAR;META-INF/application.xml;xml;context-root;1;valeur EAR;_TrackingEAR;META-INF/application.xml;xml;context-root;2;valeur2... (2 Replies)
Discussion started by: subin_bala
2 Replies

2. Shell Programming and Scripting

How to insert values in 1st occurance out of two occurance in a file

Hi I have a file which contains the following two lines which are same But I would like to insert the value=8.8.8.8 in the 1st occurance line and value=9.9.9.9 in the 2nd occurance line. <parameter name="TestIp1" value=""> <parameter name="TestIp1" value=""> Please suggest (1 Reply)
Discussion started by: madhusmita
1 Replies

3. Shell Programming and Scripting

How can I match lines with just one occurance of a string in awk?

Hi, I'm trying to match records using awk which contain only one occurance of my string, I know how to match one or more (+) but matching only one is eluding me without developing some convoluted bit of code. I was hoping there would be some simple pattern matching thing similar to '+' but... (9 Replies)
Discussion started by: jonathanm
9 Replies

4. Shell Programming and Scripting

search and replace the last occurance of a match in a file

HI please let me know if there is any command to search and replace only the last occurence of a string in aline. Eg: " This cat is a cat with a tail longer of all cat." I need to replace only the last "cat" in the above line. thanks (3 Replies)
Discussion started by: harikris614
3 Replies

5. Shell Programming and Scripting

awk to replace second occurance

#original file . . ~ ~ Index=2 xxx replace #dont replace 1st occurance yyy Index=2 xxx replace #substitue replace with "REPLACE" yyy Index=2 xxx replace #substitue replace with "REPLACE" yyy Index=3 xxx replace (3 Replies)
Discussion started by: cjjoy
3 Replies

6. Shell Programming and Scripting

search pattern and replace x-y characters in nth line after every match

Hi, I am looking for any script which can do the following. have to read a pattern from fileA and copy it to fileB. fileA: ... ... Header ... ... ..p1 ... ... fileB: .... .... Header (3 Replies)
Discussion started by: anilvk
3 Replies

7. Shell Programming and Scripting

Search and replace only the first occurance

Hi, I need to search a string and replace with nothing, but only the First occurring string using sed/perl/awk (3 Replies)
Discussion started by: suraj.sheikh
3 Replies

8. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

9. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

10. Shell Programming and Scripting

Perl:Regex for Search and Replace that has a flexible match

Hi, I'm trying to match the front and back of a sequence. It works when there is an exact match (obviously), but I need the regex to be more flexible. When we get strings of nucleotides sometimes their prefixes and suffixes aren't exact matches. Sometimes there will be an extra letter and... (2 Replies)
Discussion started by: jdilts
2 Replies
COLLATOR_SORT_WITH_SORT_KEYS(3) 					 1					   COLLATOR_SORT_WITH_SORT_KEYS(3)

Collator::sortWithSortKeys - Sort array using specified collator and sort keys

	Object oriented style

SYNOPSIS
public bool Collator::sortWithSortKeys (array &$arr) DESCRIPTION
Procedural style bool collator_sort_with_sort_keys (Collator $coll, array &$arr) Similar to collator_sort(3) but uses ICU sorting keys produced by ucol_getSortKey() to gain more speed on large arrays. PARAMETERS
o $coll -Collator object. o $arr -Array of strings to sort RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 collator_sort_with_sort_keys(3) example <?php $arr = array( 'Kopfe', 'Kypper', 'Kopfe' ); $coll = collator_create( 'sv' ); collator_sort_with_sort_keys( $coll, $arr ); var_export( $arr ); ?> The above example will output: array ( 0 => 'Kopfe', 1 => 'Kypper', 2 => 'Kopfe', ) SEE ALSO
Collator constants, collator_sort(3), collator_asort(3). PHP Documentation Group COLLATOR_SORT_WITH_SORT_KEYS(3)
All times are GMT -4. The time now is 05:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy