vendredi 26 mai 2017

Filter text file based on column value

I have a text file with 26 columns and have to filter rows if column 22 has the value of '1', '2' or '3' (out of 6). I have two filter criteria to follow

If Column 22 has value '1', '2' or '3', then remove anything less than 10 and greater 100 (based on column 5) AND remove anything less than 5.0 (this column has decimals) (based on column 13).

I am not sure how to insert the condition of do the following only if column 22 has the following values of 1 to 3 and retain the other rows as it is in the output

awk -F "\t"  'NR==1; NR>1 {if ($5 > 10 && $5<100 && $13>5.0) print $0}' input.txt > output.txt

Any help is appreciated. Thank you

Visual Basic Doesn't Recognize If Statement

My VBA code, copied from http://ift.tt/1tKpygU, will open the excel sheet but also says the strPath doesn't exist. It is supposed to autopopulate with some information from the emails but nothing is inputted. I have used both of these paths (the reason is beneath them).

    strSheet = "Job.xlsx"
    strPath = "C:\Users\name\Documents\"
    strSheet = strPath & strSheet

    strSheet = "Job.xlsx"
    strPath = "C:\Users\user\Desktop\"
    strSheet = strPath & strSheet

The location (from right-click, then selecting properties) is:
C:\Users\user\Desktop .... This opens up the sheet, but nothing is autopopulated

If I open up the sheet, and go to options -> save, then the default location is: C:\Users\user\Documents .... This doesn't open up the sheet

My questions:

  1. Why is the pathway not recognized?

  2. And why is the auto-population not working?

I assume the second one is intrinsically tied to the first question but if it isn't, I verbatim copied the code from the URL in the first line and plan on customizing after getting a working prototype.

Batch file, string variable comparison, if statement

I am trying to compare the logs of a file with a plain string, but it is not getting into if comparison. I am getting " Connect failed" as my 2nd token in echo statement, but not getting any result of IF statement.

@echo off
rem start cmd.exe
for /f "tokens=2 delims=:" %%n IN (C:\Users\rohit.bagjani\Desktop\result\telnetresult.txt) DO (
    SET str1 = " Connect failed"
    echo %%n
    if \i %str1%==%%n echo "true"
)
echo.
pause

Rails detect if object is session table

I use rails 3.2. I try to add a global check on a field of my model called account_id. My problem is that there are tables that not have this field like sessions table and others. So I have my object self and I use if condition like

if self.name.to_s!="Base" and self.name!="Session"

but the session object passed the if condition, below the error

PG::UndefinedColumn: ERROR: column sessions.account_id does not exist

How I can detect if self is session object? I see that in other case self in my function is for example NamTable+attributes ex Base[id:ecc]

Array iteration and if-statements in Action Creator in React Native

I have a ScrollView with data and I am currently implementing searchBar on the same page. Where would be a better practice to shrink the amount of data, that is retrieved from the firebase database based on the user's input in searchBar? 1. In the Action Creator that is currently deployed to simply fetch all the data from the database? 2. In the component itself? 3. Somewhere else?

I am planning to use lodash plugin and its .each method to iterate through the retrieved data and inside the .each method, I will use an if-statement in order to determine whether the current word in the iteration process has the string, that was retrieved from the search field. If it has - I add it to the new array, else - do nothing.

(jQuery) check if array value empty

I'm trying to check if array beda[i].person.name value is empty. But it keeps ignoring it. I can't figure out what I'm doing wrong with if statement

$.ajax({
    url: link,
    method: 'GET',
    success: function (beda) {
        console.log(beda);

        for(var i = 0; i < beda.length; i++){
           $("ul").first().append( "<li>" + beda[i].person.name + " ... " + beda[i].character.name + "</li>");
           console.log(beda[i].person.name)

        if ( beda[i].person.name == '' ||  beda[i].person.name == null ||  beda[i].person.name == undefined || beda[i].person.name.lenght == 0) {
            $("ul").first().append( "<li>" + "No names found!" + "</li>");
     }
    }
  }
});

My if-else statements aren't doing the things that are in the second and third "else if"

Ignore the fact that the text is in swedish (if you can).

The problem is that when i am running the program and i press "yes" on the first two questions that pop up, the first if statement works fine, but whenever i press, for example "yes" then "no", nothing happens, and i think it's because this else if statement is after the first if statement, so it's like skipping the ones after the first if statement, would really appreciate some help.

import javax.swing.JOptionPane;

public class Slutuppgift extends javax.swing.JFrame {

public Slutuppgift() {
    initComponents();
}                                       

    Object[] options = {"Osäker",
                "Nej",
                "Ja"};

int svar_1 = JOptionPane.showOptionDialog(null,
"Är bilden tagen i europa? "
,
"Fråga 1",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null);



int svar_2 = JOptionPane.showOptionDialog(null,
"Är det vatten med i bilden?"
,
"Fråga 2",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null);

 if (svar_1 == 1 && svar_2 == 1){
    int svar_3 = JOptionPane.showOptionDialog(null,
"Är platsen på bilden associerad med hasardspel?"
,
"Fråga 3",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null);   


if (svar_3 == 2)
JOptionPane.showMessageDialog(null,"Du tänkte på Vita Huset");
}

else if (svar_3 == 1){
JOptionPane.showMessageDialog(null,"Du tänkte på Las Vegas");
}

else if (svar_3 == 0){
JOptionPane.showMessageDialog(null,"Du tänkte inte på någon bild alls, du klickar bara på osäker");
}

else if (svar_1 == 2 && svar_2 == 1){
int svar_4 = JOptionPane.showOptionDialog(null,
"Är det mycket grönska på bilden?"
,
"Fråga 3",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null); 

if (svar_4 == 2){
    int svar_5 = JOptionPane.showOptionDialog(null,
"Finns det moln på bilden?"
,
"Fråga 4",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null);

if(svar_5 == 2){
    JOptionPane.showMessageDialog(null,"Du tänkte på Eiffeltornet");
}    
else if (svar_5 == 1){
    JOptionPane.showMessageDialog(null,"Du tänkte på lutande tornet i Pisa");
}
} 


else if (svar_1 == 1 && svar_2 == 2){
    int svar_6 = JOptionPane.showOptionDialog(null,
"Är platsen associerad med musik?"
,
"Fråga 3",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null); 
}    

else if (svar_1 == 2 && svar_2 == 2){
    int svar_7 = JOptionPane.showOptionDialog(null,
"Är byggnaden gammal?"
,
"Fråga 3",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options, null); 

        int svar_6 = 0;

if (svar_7 == 2){
    JOptionPane.showMessageDialog(null,"Du tänkte på Big Ben");
}

else if (svar_7 == 1){
    JOptionPane.showMessageDialog(null,"Du tänkte på Turning Torso");
}


}                                        

private void bild1MouseClicked(java.awt.event.MouseEvent evt) {                                   

}                                  

public static void main(String args[]) {

    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://ift.tt/1cNmMj1 
     */
    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(Slutuppgift.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Slutuppgift.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Slutuppgift.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Slutuppgift.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>


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

// Variables declaration - do not modify                     
private javax.swing.JLabel bild1;
private javax.swing.JLabel bild2;
private javax.swing.JLabel bild3;
private javax.swing.JLabel bild4;
private javax.swing.JLabel bild5;
private javax.swing.JLabel bild6;
private javax.swing.JLabel bild7;
private javax.swing.JLabel bild8;
private javax.swing.JLabel bild9;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel välj;
// End of variables declaration                   

}