Pregunta

I have a big but well formatted file 'A'. The first column stores the name of each row. I have another file 'B' stores the names which I am interested in. How can I select the rows having a name in file 'B'? This is simple in idea, but I am unfamiliar with LINUX.

File 'A': the data file. The first column is the name, separated with the 2nd column by \tab. The other columns are separated by comma.

col1    0.1111,0.2222,0.33333,0.4444
col2    0.1111,0.2222,0.33333,0.4444
col3    0.1111,0.2222,0.33333,0.4444
col4    0.1111,0.2222,0.33333,0.4444

File 'B': the rows with interest, stored in one column.

col1
col3
col4
¿Fue útil?

Solución

grep in A for every line in B:

for f in `cat B`; do grep -w "^$f" A >> output.txt; done

or simpler

grep -f B A > output.txt

please note that the lines in B need to be valid regular experssions

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top