I have two files which are of the following format:
File1:
Unnamed
Unnamed
Boston
Unnamed
New_York
Unnamed
File2:
San_Francisco
Chicago
Portland
Austin
Orlando
Los_Angeles
In the case where an entry in File1 is "Unnamed", I want to output the name from the same line in File2. In the case where the entry in File1 is a name, then I want to output the name from File1.
I want the output to be a file, preferably into File 2, although having the output as File3 would be OK too.
I'm new to using bash, and I can't seem to figure out how to do this. Thanks.
I appreciate the responses. I have tried each one and here is some feedback..
pmm: I also have variable names as my filenames in my script. For example:
nawk '
{ if ( FILENAME == "/files/temp/$1oldNames" ) _[FNR]=$0
if ( FILENAME == "/files/temp/$1newNames" && _[FNR] == "Unnamed" ) _[FNR]=$0
}
END { for ( i=1; i<= FNR; i++ ) print _ }
' /files/temp/$1oldNames /files/temp/$1newNames > /files/temp/$1mergedNames
Even if I harcode the file names I get a blank file3.
rikxik: That just makes file3 just like file1
summer_cherry: This works great except I realized that in file1 and file2, not only does each line have a name, but it also has enough space characters so that each line is 15 characters long, and I need to preserve the spaces (so when I merge it with other data the columns are maintained), or add spaces out to 15 for each line in file3.