sed, awk, or something...help meeeeeeeeeee

Joerg Bergmann email at jbergmann.de
Mon Sep 28 17:48:52 UTC 2009


Am 28.09.2009 19:38, schrieb Kanwar Ranbir Sandhu:
> Hi All,
>
> I don't know if I should use sed for what I'm about to ask, but it seems
> like a good idea.  If awk is better, or something else entirely, that's
> fine too.
>
> I have two files.  File "1" looks like this:
>
> AA
> BB
> CC
> DD
>
> AA
> BB
> CC
> DD
>
> File "2" looks like this:
>
> BBBB1
> BBBB2
> BBBB3
>
> So, "BB" in file "1" always occurs in the same spot (i.e. between lines
> AA and CC).  Knowing that, how do I replace the first occurrence of "BB"
> in file "1" with "BBBB1" from file 2, the second occurrence of "BB" in
> file "1" with "BBBB2" from file 2, and so on?
>
> I think a bash 'for' or 'while' loop may be useful here, too.  But, it's
> the sed/awk/whatever bits I don't know how to do.  I've read some of the
> man/info page, looked up sed help on the net, etc.  I'm still not sure
> how to do the above with sed.
>
> Thanks in advance!
>
> Regards,
>
> Ranbir
>    
Probably it's not what you want, but I would prefer writing a

50 lines standard C program for that task...

Joerg




More information about the fedora-list mailing list