从抛出错误的变量中减去一个数字

时间:2017-01-12 01:55:27

标签: shell variables grep numbers subtraction

我正在使用以下代码来grep通过在第2列和第3列中添加和减去1来计算的值,如下所示:

 while read intron ; do
   start=$(grep -w $intron ../file_to_be_grepped_from | awk '{print $2}')
   end=$(grep -w $intron ../file_to_be_grepped_from | awk '{print $3}')
   str=$(($start-1))
   en=$(($end+1))
   grep -w $str ../file_to_be_grepped_from
   grep -w $en ../file_to_be_grepped_from
   echo $intron 
  done <  file

然而,我正在添加并从第3列和第2列中减去1的部分,我收到错误为“46844234-1:表达式中的语法错误(错误标记为”46844234-1“)”我正在收集的文件(file_to_be_grepped_from)。它们被grepped的文件中的行如下所示:

  chr9  46844104    46844233    ENSG00000226007:E2  +
  chr9  46844104    46846023    ENSG00000226007:I2  +
  chr3  21584308    21584487    ENSG00000225542:E1  +
  chr3  21620681    21620873    ENSG00000225542:E2  +

我试图弄清楚错误是由于重复行还是其他因素,我尝试了从变量中减去数字的所有可能语法。

2 个答案:

答案 0 :(得分:1)

str=$(grep -w $intron ../file_to_be_grepped_from | awk '{print($2-1)}')
en=$(grep -w $intron ../file_to_be_grepped_from | awk '{print($3+1)}')

答案 1 :(得分:0)

请尝试:

public class welcome extends javax.swing.JFrame {

public welcome() {
    initComponents();
}

@SuppressWarnings("unchecked")

private void initComponents() {

    jPanel = new javax.swing.JPanel();
    jLabel_UnameDisplay = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    jLabel_UnameDisplay.setBackground(new java.awt.Color(102, 255, 102));
    jLabel_UnameDisplay.setOpaque(true);
    jPanel.add(jLabel_UnameDisplay, new org.netbeans.lib.awtextra.AbsoluteConstraints(93, 69, 199, 126));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    pack();
}                   


public static void main(String args[]) {

    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(welcome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(welcome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(welcome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(welcome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new welcome().setVisible(true);
        }
    });
}

private javax.swing.JLabel jLabel_UnameDisplay;
private javax.swing.JPanel jPanel;

}