Search Results

Search: Posts Made By: ureddy
Forum: AIX 03-29-2017
3,615
Posted By Don Cragun
I didn't say to run sed twice; I said to run sed...
I didn't say to run sed twice; I said to run sed once using the global substitution twice. Running that global substitute twice will take care of ALL occurrences of the pattern you said you wanted...
Forum: AIX 03-29-2017
3,615
Posted By Don Cragun
Another solution is to just run your global...
Another solution is to just run your global substitution twice:
sed -e 's/|\.|/||/g' -e 's/|\.|/||/g'
which, with your latest sample input:
123.5|ABC.|.|.|.
234.4|DEF|.|.|.|.|.|
produces the...
Forum: AIX 03-29-2017
3,615
Posted By MadeInGermany
With the g modifier, what matched once is out of...
With the g modifier, what matched once is out of scope for another match.
But a loop can do it
sed '
:L
s/|\.|/||/
tL
'Another solution is perl: by using a look-ahead an RE substitution with g...
Forum: AIX 03-28-2017
3,615
Posted By Scott
$ sed "s/\.|/|/g" file 123.5|ABC|||. ...
$ sed "s/\.|/|/g" file
123.5|ABC|||.
234.4|DEF||||||

This doesn't really satisfy the "requirement to replace consecutive occurence of same string", it only removes full-stops.
1,263
Posted By RudiC
Strange... tryawk 'NR==FNR {T[$1]=$2;...
Strange... tryawk 'NR==FNR {T[$1]=$2; next}
{for (i in T) if (2 <= gsub (i,"&")) {
gsub (i, T[i])
...
1,661
Posted By MadeInGermany
Previous solution optimized: sed 's#.*#s,&,2g#'...
Previous solution optimized:
sed 's#.*#s,&,2g#' FILE2.txt >FILE2.sed
sed -f FILE2.sed FILE1.txt >RESULT.txt
Now an awk solution that does not do a RE substitution, but a substitution word by word:...
1,661
Posted By cjcox
Assuming GNU sed.... Create the sed file...
Assuming GNU sed....

Create the sed file using FILE2.txt:

sed 's#\([^,]*\),\(.*\)#s/\1/\2/2g;t#' <FILE2.txt >FILE2.sed


Use that FILE2.sed as the commands for sed:

sed -f FILE2.sed...
Showing results 1 to 7 of 7

 
All times are GMT -4. The time now is 03:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy