Menu

If else condition in shell script with $? and grep command

In shell script condition check is very easy and simple using if else statements. Here is a example which we would like to discuss with our readers.

Scenario: We have a variable that contains long string value, user wants to find matching value from given string and perform check whether that text/character has matched from string value or or not.


#Program in Bash Shell
Line 1: CHECK_SOURCE="[main] INFO com.adobe.jcr.checknode.existence - Node does not exist"
line 2: echo $CHECK_SOURCE | grep -w -o -i 'Node exists'
Line 3: if [ $? == 0 ]; then
Line 4:        echo " matched"
Line 5: else 
Line 6: echo "not matched" 
Line 7: fi 

Explanation:

In line 1 we have declared a variable CHECK_SOURCE which have some value.
In line 2 we are finding text "Node exists" in value of variable CHECK_SOURCE using grep command.
In line 3 using if statement we are checking number of matches from last executed statement. $? sign will return number of matches. If text passed in grep command will find some matching text in variable then $? will number of matching otherwise it will return zero. 



Import and Export Java project in a Zip file in Eclipse

Importing a Java Project from a Zip File into a Workspace

In the past, we have imported projects as JAR files into the src folder of an existing project. For this course, it will probably be easier to import projects directly into the workspace. This is especially true with shader programs since they often require additional text file resources (in our case, shader source code in simple text files) that we didn’t encounter in previous Java programs. When I create demo projects for you, I will often create them for you as zip files.

To import a Java project from a zip file into a workspace:

1. Open Eclipse and navigate to the workspace. To make life easier for us all, make that the workspace that includes your other JOGL projects.
2. Select File…Import…
3. Expand General, select Existing Projects into Workspace and click Next.
4. Click the Select archive file radio button and browse for the zip file containing the project.
5. Click Finish and the project should appear in your workspace. Note: Eclipse will not import a project if you already have one with the same name. If you still want to proceed, rename the existing one and try importing again.

Exporting a Java Project to a Zip File

If you want to export one of your projects to a zip file, do this:

1. Left-click the project name in Package Explorer that you want to export (For example, if the project is named ColorMixer, left-click on that name).
2. Select File…Export…
3. Expand General, select Archive File, and click Next.
4. In the Export dialog, make sure that your selected project is checked and that the options Save in zip format and Create directory structure for files are both selected.
5. Browse for a location to save the archive file. A zip extension will be added automatically.
6. Click Finish and your project should be saved as a zip file in the location you requested.

Google Analytics questions and answers for beginner

1. What would you use to compare two date ranges in a report?

  1. Hourly, Day, Week, Month views in the time graph
  2. Real-time reports
  3. Date range comparison
  4. Account selector

2. What does the “Users” metric measure?

  1. The total number of visits to your website
  2. Users that had at least one session on your site in the given date range
  3. Users that landed on the homepage of your website
  4. Users who have signed up to an email newsletter on your website

3. In Google Analytics, what is the “Bounce Rate”?

  1. The number of times unique users returned to your website in a given time period
  2. The percentage of sessions in which a user exits from your homepage
  3. The percentage of total site exits
  4. The percentage of visits when a user landed on your website and exited without any interactions

4. In Google Analytics, what is a “dimension”?

  1. The total amount of revenue a business has made in a given date range.
  2. An attribute of a data set that can be organized for better analysis.
  3. A comparison of data between two date ranges.
  4. A report that offers information about your audience.

5. In Google Analytics, what is a “metric”?

  1. A dimension that can help you analyze site performance.
  2. The dates in your date range.
  3. A segment of data separated out in a report for comparison.
  4. The numbers in a data set often paired with dimensions.

6. In Google Analytics, what is a “secondary dimension”?

  1. An additional widget you can add to a dashboard for more specific analysis.
  2. An additional metric you can add to a report for more specific analysis.
  3. An additional dimension you can add to a report for more specific analysis.
  4. A visualization that allows you to view understand the impact of your data.

7. If you wish to see if report data is performing above or below the website average, which Google Analytics visualization should you choose?

  1. Pivot view
  2. Comparison view
  3. Performance view
  4. Percentage view

8. How do you increase the amount of data in a sampled Google Analytics report?

  1. Choose “Greater precision” in the sampling pulldown menu
  2. Choose “Faster response” in the sampling pulldown menu
  3. Apply additional filters
  4. Remove the Secondary Dimension

9. By selecting “Share Template Link” you can share your dashboard and your data with another user.

  1. True
  2. False

10. If you share a dashboard with others, they can change the information that shows on their dashboard

  1. True
  2. False

Correct Answers:

1. Date range comparison
2. Users that had at least one session on your site in the given date range
3. The percentage of visits when a user landed on your website and exited without any interactions
4. An attribute of a data set that can be organized for better analysis.
5. The numbers in a data set often paired with dimensions.
6. An additional dimension you can add to a report for more specific analysis.
7. Comparison view
8. Choose “Greater precision” in the sampling pulldown menu
9. False
10. True