Sed replace from another file

From: Matt (SPAMmchildersNO_at_gmail.com)
Date: 02/24/05


Date: Thu, 24 Feb 2005 16:57:58 -0600

I have posted here several times the last week, and you all have been so
helpful, hopefully this will be the last question... I need some help
gettting sed to replace a line in one file with a more detailed line in
another file. I'm trying to get the following to work:

$cat foo
1234
1235
1236

$cat bar
Device 1 (1235)||1235||{AEA2A6E7-FBFD-4472-92E9-8F9E2C16AF4F}
Device 2 (1236)||1236||{ASA2F2E4-FGFA-4492-8E2B-FF2A59C16B7A}
Device 3 (1234)||1234||{9D30891C-2539-4A56-A138-879F7B4988AA}

$ sed foo -e 'magical sed statement'
Device 3 (1234)||1234||{9D30891C-2539-4A56-A138-879F7B4988AA}
Device 1 (1235)||1235||{AEA2A6E7-FBFD-4472-92E9-8F9E2C16AF4F}
Device 2 (1236)||1236||{ASA2F2E4-FGFA-4492-8E2B-FF2A59C16B7A}

I have tried the follwoing to no avail:

$ sed foo -e "s;\(\|\|.*\|\|\);cat bar | grep \\\1`/g"
grep: Invalid back reference

However, I can get this to work, which lets me know that I can use the \\\1
to get the text I want to be executed in the command, but it just doesn't
seem to work with grep.

$ sed foo -e "s;\(\|\|.*\|\|\);`echo \\\1`;g"
1234
1235
1236

Does anyone know what I need to do to get this working? Any help would be
appreciated.

Thanks again,
Matt



Relevant Pages

  • problem with "find" command
    ... I am running Fedora Core 3. ... This find command worked... ... grep: /selinux/disable: Invalid argument ...
    (comp.os.linux)
  • Re: [:ascii:] character class
    ... Now grep and sed give the error "Invalid ... character class name". ... Am I misremembering? ...
    (Debian-User)
  • Re: syslog
    ... but basically "cat foo | grep XXX" is a wasted process because it has identical semantics to "grep XXX < foo". ...
    (comp.unix.solaris)
  • Re: syslog
    ... but basically "cat foo | grep XXX" is a wasted process because it has identical semantics to "grep XXX < foo". ...
    (comp.unix.solaris)
  • Re: IPFW Rule
    ... getting the message "ipfw: getsockopt: Invalid argument". ... $ sysctl -a |grep forward ... I am running 6.1- RELEASE FreeBSD 6.1-RELEASE #0. ...
    (freebsd-questions)