#
# File: copyit
#
# Purpose: To parse first file for record that contains
# a pattern, capture it in a variable, then,
# parse second file for a pattern and place
# the variable after this record.
#
# Usage: copyit <CR>
#
# Note-
# The first example program adds a copy of the record
# that contains the variable after *all* records in
# second file that contain the matched pattern!
#
# The second version of the program adds a copy of the
# record that contains the variable after *first* record
# found in second file that contains the matched pattern!
#
awk '
FILENAME == "file1" {
if( $0 ~ /acd/ ) foundit = $0
close("file1"

}
FILENAME == "file2" {
if( $0 ~ /qqq/ ) {
print
print foundit
} else print
}' file1 file2 > file3
awk '
FILENAME == "file1" {
if( $0 ~ /acd/ ) foundit = $0
close("file1"

}
FILENAME == "file2" {
if(( $0 ~ /qqq/ ) && ( !flag )) {
print
print foundit
flag = 1
} else print
}' file1 file2 > file3
# input file1
1234,abc,a12,zx,10
1235,acd,b35,dc,10
1456,cds,c25,fr,10
1290,cds,r45,fx,50
# input file2
1456,678,rrr,4679,10
1234,234,qqq,3456,10
1235,478,ddd,7890,10
1234,234,qqq,3456,10
1290,456,ttt,5867,50
1234,234,qqq,3456,10
Hope this helps!
flogrr
flogr@yahoo.com