coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When specifying multiple elements with "-e" option of join command


From: Assaf Gordon
Subject: Re: When specifying multiple elements with "-e" option of join command
Date: Thu, 30 Mar 2017 11:08:43 -0400

Hello,

> On Mar 30, 2017, at 01:41, Goto, Ryoichi <address@hidden> wrote:
> 
> [...]
> I tried executing the following command, but the record "address@hidden" 
> 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
> address@hidden 2 password 2
> address@hidden 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 <==
  address@hidden
  address@hidden
  address@hidden

  ==> file2 <==
  address@hidden 1 password 1
  address@hidden 2 password 2

  $ join -o auto -e MISSING -a 1 -j1 <(sort file1) <(sort file2)
  address@hidden 2 password 2
  address@hidden MISSING MISSING MISSING
  address@hidden 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)
  address@hidden 2 password 2
  address@hidden
  address@hidden 1 password 1

  $ join -a 1 -j1 <(sort file1) <(sort file2) \
     | awk 'NF==1 { print $0, "0 password 0" } NF!=1 { print }'
  address@hidden 2 password 2
  address@hidden 0 password 0
  address@hidden 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)
  address@hidden 2 password 2
  address@hidden XX XX XX
  address@hidden 1 password 1

  $ join -o auto -e XX -a 1 -j1 <(sort file1) <(sort file2) \
        | sed 's/XX XX XX/0 password 0/'
  address@hidden 2 password 2
  address@hidden 0 password 0
  address@hidden 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

[Prev in Thread] Current Thread [Next in Thread]