Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
Using file1 as an Index to search file2 when file1 contains extra informations

as you can read in the title Im dealing with two files. Her is the example how the look like.

file1:

Name (additional info separated by a tab from the name)

Peter Schwarzer<tab>Best friend of mine

file2:

Name (followed by a float separated by a tab from the name)

Peter Schwarzer<tab>1456

So what i want to do is use file1 one as an index for searching file2. If the Names match it should be written in file3 which should contain the Name followed by the float from file2 followed by the additional info from file1. So file3 should look like:

Peter Schwarzer<tab>1456<tab>Best friend of mine 

(everything separated by tab)

I tried grep -f to read a pattern from a file and without the additional information it works. So is there any way to get the desired result with grep or is AWK the answer?

Thanks in advance, Julian

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

give this line a try, I didn't test, but should go:

awk -F'\t' -v OFS="\t" 'NR==FNR{n[$1]=$2;next}$1 in n{print $0,n[$1]}' file1 file2 > file3
over 4 years ago · Santiago Trujillo Denunciar

0

Try this awk one liner!

awk -v FS="\t" -v OFS="\t" 'FNR==NR{ A[$1]=$2; next}$1 in A{print $0,A[$1];}' file1.txt  file2.txt > file3.txt
over 4 years ago · Santiago Trujillo Denunciar

0

To me this looks like a job for join:

join -t '\t' file1 file2

This assumes file1 and file2 are sorted. If not, sort them first:

sort -o file1 file1
sort -o file2 file2
join -t '\t' file1 file2

If you can't modify file1 and file2 (if you need to leave them in their original, unsorted state), use a temporary file:

tmpfile=/tmp/tf$$
sort file1 > $tmpfile
sort file2 | join -t '\t' $tmpfile -

If join says "illegal tab character specification" you'll have to use join -t ' ' where you type an actual tab between the single quotes (and depending on your shell, you may have to use control-V before that tab).

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda