Skip to main content
Minor formatting improvements
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

Try running just wc -l my_first_file.bed:

$ wc -l my_first_file.bed
24 my_first_file.bed
$ wc -l my_first_file.bed
24 my_first_file.bed

So, your command gets expanded by the shell to awk -v num=24 my_first_file.bed '{print $1, $2, $3, $4/num}' my_other_file.bed

awk -v num=24 my_first_file.bed '{print $1, $2, $3, $4/num}' my_other_file.bed`

which makes my_first_file.bed your awkAwk command, which of course is not valid awkAwk syntax.

One way you could solve this would be to change your wc -l my_first_file.bed command to only output the first column. For example, something like this: awk -v num=$(wc -l my_first_file.bed | cut -d' ' -f1) '{print $1, $2, $3, $4/num}' my_other_file.bed.

awk -v num=$(wc -l my_first_file.bed | cut -d' ' -f1) '{print $1, $2, $3, $4/num}' my_other_file.bed

This uses space as the delimiter for the output of cut to just pass the number of lines to your variable.

Try running just wc -l my_first_file.bed:

$ wc -l my_first_file.bed
24 my_first_file.bed

So, your command gets expanded by the shell to awk -v num=24 my_first_file.bed '{print $1, $2, $3, $4/num}' my_other_file.bed which makes my_first_file.bed your awk command, which of course is not valid awk syntax.

One way you could solve this would be to change your wc -l my_first_file.bed command to only output the first column. For example, something like this: awk -v num=$(wc -l my_first_file.bed | cut -d' ' -f1) '{print $1, $2, $3, $4/num}' my_other_file.bed. This uses space as the delimiter for the output of cut to just pass the number of lines to your variable.

Try running just wc -l my_first_file.bed:

$ wc -l my_first_file.bed
24 my_first_file.bed

So, your command gets expanded by the shell to

awk -v num=24 my_first_file.bed '{print $1, $2, $3, $4/num}' my_other_file.bed`

which makes my_first_file.bed your Awk command, which of course is not valid Awk syntax.

One way you could solve this would be to change your wc -l my_first_file.bed command to only output the first column. For example, something like this:

awk -v num=$(wc -l my_first_file.bed | cut -d' ' -f1) '{print $1, $2, $3, $4/num}' my_other_file.bed

This uses space as the delimiter for the output of cut to just pass the number of lines to your variable.

Source Link

Try running just wc -l my_first_file.bed:

$ wc -l my_first_file.bed
24 my_first_file.bed

So, your command gets expanded by the shell to awk -v num=24 my_first_file.bed '{print $1, $2, $3, $4/num}' my_other_file.bed which makes my_first_file.bed your awk command, which of course is not valid awk syntax.

One way you could solve this would be to change your wc -l my_first_file.bed command to only output the first column. For example, something like this: awk -v num=$(wc -l my_first_file.bed | cut -d' ' -f1) '{print $1, $2, $3, $4/num}' my_other_file.bed. This uses space as the delimiter for the output of cut to just pass the number of lines to your variable.