Before I've post this question, I have spent hours looking for the solutions but to no avail. Because I think it is possible but I just don't know what is the right keyword to search for.
Ok, basically what I want to achieve is really simple.
It's just that I don't want to write another file because it's merely based on the existing file content.
For HPUX /sbin/sh is a POSIX-compliant shell. POSIX does not require process substitution, which is what you are asking for. Out of the box 11i HPUX has /bin/ksh which does support it.
No, it is not. The first, although missing a closing parenthesis, is called "process substitution" and offers cut 's results as a stream on stdin for grep .
The second offers cut 's results as a list of parameters (i.e. file names) to grep . The "!" will invert cut 's exit code in sh , it will perform history expansion in bash .
Yep this awk -F"@" 'NR==FNR {a[$1];next} {if($1 in a){next;}print $1}' source.list complete.list works! And it is so flexible and thus the difference could be done both ways. Thank you so much.
The temp file removal also works. Thanks.
So, could you explain both of the codes? What does the [ -e source.temp ] acts for?
which will try to delete source.temp regardless of any other previous command, however, that would display an error if it was not found.
[ -e source.temp ] (notice the spaces after [ and before ], very important) is test. (take a look at man test), -e evaluates to true if exists, so if that is true then continue to rm -f, avoiding the error message.
Awk
-F"@" make the field separator an `@', that takes care of the format of source.list, dividing each line into two fields, before the `@' and after the `@'
NR==FNR {a[$1];next} this part is only for the first file, in this case source.list. The build-in variable NR is set to the total number of records found from all files, the build-in variable FNR is only the number of records in the current reading file, so as long as both are the same, we are reading only from the first file, if so perform the instructions on the first set of {a[$1];next} which only keeps an array named `a[name of the field]' and skip the rest of the instructions.
Now, we have the whole first file indexed in memory.
{if($1 in a){next;}print $1}' The rest is just an evaluation for the second file, if any of the records are seen already, do nothing (skip to next), otherwise, display it because is missing.