Hello,

> On Mar 30, 2017, at 01:41, Goto, Ryoichi <[email protected]> wrote:
> 
> [...]
> I tried executing the following command, but the record "[email protected]" which 
> exists only in File 1 has two pairs of character strings specified by "-e" 
> output.
> $ Join -1 1 - o 0 2.2 2.3 - a 1 - e "0 PASSWORD 0" <(sort File 1) <(sort File 
> 2)
> 
> [Actual result]
> Jiro @ yahoo.jp 0 PASSWORD 0 0 PASSWORD 0
> [email protected] 2 password 2
> [email protected] 1 password 1
> 
> If you remove the double quotes from the command line you ran, "join: extra 
> operator '/ dev / fd / 62'" and an unknown error will be displayed and say "- 
> e 0 - e PASSWORD 0" The syntax is also an error.

The "-e" parameter fills missing fields with the given value. The second file
has 4 fields, and after the join 3 fields are missing - so the string
you've set to "-e" appears multiple times.

Notice the following:

  $ head *
  ==> file1 <==
  [email protected]
  [email protected]
  [email protected]

  ==> file2 <==
  [email protected] 1 password 1
  [email protected] 2 password 2

  $ join -o auto -e MISSING -a 1 -j1 <(sort file1) <(sort file2)
  [email protected] 2 password 2
  [email protected] MISSING MISSING MISSING
  [email protected] 1 password 1

I can suggest two work-arounds, which work with your specific files:

Option #1:
Because 'file1' has only one field, we know implicitly that
any joined line which still has one field in the output
did not have a matching record in the second file.
Then, a simple AWK script can add the needed password:

  $ join -a 1 -j1 <(sort file1) <(sort file2)
  [email protected] 2 password 2
  [email protected]
  [email protected] 1 password 1

  $ join -a 1 -j1 <(sort file1) <(sort file2) \
     | awk 'NF==1 { print $0, "0 password 0" } NF!=1 { print }'
  [email protected] 2 password 2
  [email protected] 0 password 0
  [email protected] 1 password 1


Option #2:
Use "-e" to mark lines with missing values,
then detect and replace then with sed:

  $ join -o auto -e XX -a 1 -j1 <(sort file1) <(sort file2)
  [email protected] 2 password 2
  [email protected] XX XX XX
  [email protected] 1 password 1

  $ join -o auto -e XX -a 1 -j1 <(sort file1) <(sort file2) \
        | sed 's/XX XX XX/0 password 0/'
  [email protected] 2 password 2
  [email protected] 0 password 0
  [email protected] 1 password 1


Of course these are just examples which can be used
as basis for similar variations.

Hope this helps,

regards,
 - assaf



Reply via email to