Pregunta

I have tab-separated files (sorry I don't know how to format it, should not be space, but tab).

""  "logFC" "logCPM"    "LR"    "PValue"    "FDR"
"A1BG"  -0.2    -1.5    5.3 0.0 0.1

Mark that columns- and rows- names have "" around them, the values have not. And again, its tab-separated.

My code is:

cat file1.csv file2.csv file3.csv | gawk 'NR==1 {if ($1=="something" || $1=="something2") print $1,$2,$4,;}' >  test1.txt

"test1.txt" is however empty and I don't know why..

So if I ran:

cat file1.csv file2.csv | gawk 'NR==1 {if ($1=="A1BG") print $1,$2,$4,;}' >  A1BG.txt

I want A1BG.txt to look like:

""  ""  "logFC" "LR"
file1.csv "A1BG"    -0.2 5.3
file2.csv "A1BG"    y x
¿Fue útil?

Solución

What are you hoping to accomplish with NR==1 in your awk action? That means your action will only execute for the first line of your input. So regardless of how many lines of input you feed to awk, that action will (a) only run once, and (b) may not output anything, unless the first line happens to match something or something2.

I'm not completely clear on what you're trying to do, but maybe this will help:

gawk '
  NR==1 {print}
  $1 == "something" || $1 == "something2" {print FILENAME, $1,$2,$4}
' file1.csv file2.csv file3.csv >  test1.txt

This will run for every line, instead of just the first one. If the first field is something or something2, it will print out fields 1, 2, and 4.

UPDATE: I've modified this to print the first line of the input.

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