[ale] multi-file string swap

Jim Kinney jim.kinney at gmail.com
Tue Aug 4 17:09:34 EDT 2009


OK. Last technique hunt for the day. really.

2 files, /etc/hosts and /home/foo/.ssh/known_hosts (that makes for
long lines and different location delimeters)

hosts has :

ip name1 name2

known_hosts has:
name1,ip ssh-rsa <long string>

I need to change name1 in known_hosts to name2 from /etc/hosts

I'm looking at creating a string from each line in /etc/hosts as
name1,ip and doing a sed substitution for name2,ip in known_hosts.

A fun thing is not all hosts files have name2. Those I don't want to
tinker with anywhere.

So I have the following which outputs a space separated
pattern/substitution set: (yay!)

grep -v "^127" </etc/hosts | grep "^[0-9]" | awk '{$2=tolower($2); if
($3)  print $2","$1,$3","$1 }'

Next step is to actually do the substitution. I tried adding more to
the above line as:

| awk '{ system(" sed -i \"s/$1/$2/\" known_hosts ") }'

but no joy:

sed: -e expression #1, char 0: no previous regular expression

So I've poked and fiddled with the " and ' and added backslashes until
it looks like perl code with no solution yet.

So then I tried just echo'ing the strings thinking they will show up
as positional parameters $1 and $2.

| echo "$1 $2" gave nothing. I'm rather puzzled and expecting it's
something simple yet subtle I'm missing.

Ideas?

-- 
-- 
James P. Kinney III
Actively in pursuit of Life, Liberty and Happiness


More information about the Ale mailing list