简体   繁体   中英

Using multiple awk statements in a linux command

I am executing a bash script in php file.

  1. I have a text file.
  2. I have to extract last 100 lines of the file.
  3. In these 100 lines I have to extract lines with character "A" in third column.
  4. Among these shortlisted lines I have to get the line number of the line whose second column has number "2".

This is my code, which is not providing any output.

<?php

$eff="195";
$chain="B";
$struct_pos="2";

$pre_line=exec("tail $i.dssp -n $eff | awk '$3==$chain'| awk -F' ' -v var=$struct_pos '{if ($2==var) print FNR}'");

?>

However, following codes works properly, in which I have removed one of the awk statements.

$pre_line=exec("tail $i.dssp -n $eff | awk -F' ' -v var=$struct_pos '{if ($2==var) print FNR}'");

$pre_line=exec("tail $i.dssp -n $eff | awk '$3==$chain'");   

What is the solution to this problem ?

尝试这个..,

$pre_line=exec("tail $i.dssp -n $eff | awk '$3==\"'$chain'\"'| awk -F' ' '{if ($2=='$struct_pos') print FNR}'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM