"It seemed like a good idea at the time."
Nothing beats good old fashion awk when it comes to problem solving :-). Here is one such example:
[ircuser] is there any command or quick way to do like,say i have two strings, "tes**ng" and "lkmtide" . need to replace the '*' in the first string with the exact characters in the second string. so, "tes**ng" changes to "testing"
[ircuser] cmihai, here the issue is * is not fixed to two chars... it can be from one to len-2
# Author: Criveti Mihai, 2007.
# This program is free software.
# It comes without any warranty, to the extent permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the
# Do What The Fuck You Want To Public License, Version 2
# as published by Sam Hocevar.
# See http://sam.zoy.org/wtfpl/COPYING for more details.
# Usage: cat file | awk -f change_stars_and_stuff.awk > output
FS = " ";
string1 = $1;
string2 = $2;
position = index( string1,"*");
finalstring = substr(string2,position,1);
} while (position != 0)
The input file would look something like this (from what I gather anyway):
$ cat file
And now, let's take our little script for a test drive:
$ cat file | awk -f change_stars_and_stuff.awk
Well, that did it :-). Good old fashion AWK to the rescue!