Page not found – ShopingServer Wiki http://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Sun, 27 Oct 2019 20:48:36 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 http://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki http://wiki.shopingserver.com 32 32 Awk Floating Point Number Addition Results Are Unexpected http://wiki.shopingserver.com/awk-floating-point-number-addition-results-unexpected/ http://wiki.shopingserver.com/awk-floating-point-number-addition-results-unexpected/#respond Sat, 06 Jan 2018 10:09:47 +0000 http://wiki.shopingserver.com/?p=18583 I am using awk to grep ‘foo’ from a text file and cacluate sum of field # 7. But, result is rounded to an integer. I need exact result such as 385858.66 and not 385858 using the following command:

grep ‘foo’ 2012-2013.txt | awk ‘BEGIN{ sum=0.0}{ sub(“,”,””,$7); sum +=$7}END{ print “$” sum}’

$682444

I want $682444.57 as output. How can I force “awk” to do floating point math?

 

Floating-point numbers or “real” numbers are that have a fractional part. awk uses double-precision floating-point numbers to represent all numeric values. In other words, all numbers in awk are floating-point numbers i.e. all calculation done using floating-point numbers.

Example: Awk floating point calculation

The following example uses a file called trade.txt, which contains a list of week names as well as four profit values per week:

week1 12.5 12.5 13.5 18.5

week2 11.5 11.10 12.10 13.70

week3 8.5  8.10 8.5 12.5

week4 9.5 11.5 13.5 16.5

week5 8 7 13 17

The following awk program takes the file trade.txt and prints the sum of all four values:

awk  { sum = $2 + $3 + $4 + $5; print $1, sum }  trade.txt

Sample outputs:

week1 57

week2 48.4

week3 37.6

week4 51

week5 45

The following awk program takes the file trade.txt and prints the average of all four values:

awk  { sum = $2 + $3 + $4 + $5; avg = sum/4; print $1, sum , avg}  trade.txt

Sample outputs:

week1 57 14.25

week2 48.4 12.1

week3 37.6 9.4

week4 51 12.75

week5 45 11.25

To avoid surprises use printf to format text to make your output more beautiful and meaningful:

awk  { sum = $2 + $3 + $4 + $5; avg = sum/4; printf  %s: $%.2f ($%05.2f)\n ,$1, sum, avg}  trade.txt

OR

awk  { sum = $2 + $3 + $4 + $5; avg = sum/4; printf  %s: $%.2f ($%5.2f)\n ,$1, sum, avg}  trade.txt

Sample outputs:

week1: $57.00 ($14.25)

week2: $48.40 ($12.10)

week3: $37.60 ($ 9.40)

week4: $51.00 ($12.75)

week5: $45.00 ($11.25)

To fix your problem, replace the following awk code

grep  foo  2012-2013.txt  | awk  BEGIN{ sum=0.0}{ sub( , ,  ,$7); sum +=$7}END{ print  $  sum}

with:

grep  foo  2012-2013.txt  | awk  BEGIN{ sum=0.0}{ sub( , ,  ,$7); sum +=$7}END{  printf  $%.2f\n , sum}

You can skip the grep command and use awk as follows to match and perform sum of all $7:

awk  /foo/{ sub( , ,  ,$7); sum = old + $7; old=sum}END{ printf  $%.2f\n , sum}  2013-2014.txt

Recommended readings

See awk(1) for more info.

 

 

]]>
http://wiki.shopingserver.com/awk-floating-point-number-addition-results-unexpected/feed/ 0
CentOS / RHEL 6: Install Midnight Commander File Manager http://wiki.shopingserver.com/centos-rhel-6-install-midnight-commander-file-manager/ http://wiki.shopingserver.com/centos-rhel-6-install-midnight-commander-file-manager/#respond Sat, 06 Jan 2018 08:45:31 +0000 http://wiki.shopingserver.com/?p=18483 I

am a new CentOS Linux user. How do I install GNU mc (Midnight Commander) on Red Hat Enterprise Linux or CentOS Linux server version 5.x/6.x using bash command line?

 

GNU Midnight Commander (also known as mc) is a free and visual file manager, licensed under GNU General Public License. It is a clone of Norton Commander. It was started by Miguel de Icaza in 1994. It’s a feature rich full-screen text mode application that allows you to copy, move and delete files and whole directory trees, search for files and run commands in the subshell. Internal viewer and editor are included.

Install Midnight Commander (mc) On Centos / RHEL / Fedora Linux

Open the Terminal or login to remote server using ssh client. Type the following yum command to install mc:

# yum install mc

 

Sample outputs:

Loaded plugins: product-id, rhnplugin, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

This system is receiving updates from RHN Classic or RHN Satellite.

Setting up Remove Process

Resolving Dependencies

–> Running transaction check

—> Package mc.x86_64 1:4.7.0.2-3.el6 will be erased

–> Finished Dependency Resolution

 

Dependencies Resolved

 

================================================================================

Package  Arch         Version                Repository                   Size

================================================================================

Removing:

mc       x86_64       1:4.7.0.2-3.el6        @rhel-x86_64-server-6       5.4 M

 

Transaction Summary

================================================================================

Remove        1 Package(s)

 

Installed size: 5.4 M

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Erasing    : 1:mc-4.7.0.2-3.el6.x86_64                                    1/1

Verifying  : 1:mc-4.7.0.2-3.el6.x86_64                                    1/1

 

Removed:

mc.x86_64 1:4.7.0.2-3.el6

 

Complete!

{root@cyberciti.biz }#

{root@cyberciti.biz }# yum install mc

Loaded plugins: product-id, rhnplugin, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

This system is receiving updates from RHN Classic or RHN Satellite.

Setting up Install Process

Resolving Dependencies

–> Running transaction check

—> Package mc.x86_64 1:4.7.0.2-3.el6 will be installed

–> Finished Dependency Resolution

 

Dependencies Resolved

 

================================================================================

Package  Arch         Version                 Repository                  Size

================================================================================

Installing:

mc       x86_64       1:4.7.0.2-3.el6         rhel-x86_64-server-6       1.6 M

 

Transaction Summary

================================================================================

Install       1 Package(s)

 

Total download size: 1.6 M

Installed size: 0

Is this ok [y/N]: y

Downloading Packages:

mc-4.7.0.2-3.el6.x86_64.rpm                              | 1.6 MB     00:00

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : 1:mc-4.7.0.2-3.el6.x86_64                                    1/1

Verifying  : 1:mc-4.7.0.2-3.el6.x86_64                                    1/1

 

Installed:

mc.x86_64 1:4.7.0.2-3.el6

 

Complete!

How do I use mc?

Simply type the following command:

$ mc

 

Sample outputs:

Fig.01: mc in action

As you can see the screen of the Midnight Commander is divided into four parts. Almost all of the screen space is taken up by two directory panels. By default, the second line from the bottom of the screen is the shell command line, and the bottom line shows the function key labels. The topmost line is the menu bar line. The menu bar line may not be visible, but appears if you click the topmost line with the mouse or press the F9 key.

mc syntax and command examples

Here are some useful examples and syntax:

FORCE BLACK AND WHITE DISPLAY FOR MC

$ mc -b

FORCE COLOR MODE FOR MC

$ mc -c

DISABLE MOUSE SUPPORT FOR MC

$ mc -d

START MC WITH THE INTERNAL EDITOR

$ mc -e

$ mc -e /path/to/file.txt

mc Command Installation and Usage demo

This tutorial is also available in a video format:

 

(Video 01: RHEL / CentOS Linux Install GNU Midnight Commander Tutorial)

For more information see mc(1) and the official GNU midnight commander home page.

 

 

]]>
http://wiki.shopingserver.com/centos-rhel-6-install-midnight-commander-file-manager/feed/ 0
How to Add a Frequently Asked Questions – FAQs section in WordPress http://wiki.shopingserver.com/how-to-add-a-frequently-asked-questions-faqs-section-in-wordpress-2/ http://wiki.shopingserver.com/how-to-add-a-frequently-asked-questions-faqs-section-in-wordpress-2/#respond Tue, 19 Dec 2017 16:06:20 +0000 https://www.shopingserver.net/?p=16950 When launching a new product or website, you may need to add a FAQs section in WordPress. You can add a new page with all the frequently asked questions (FAQs), but in most cases FAQs grows as your product evolves and as your customer base grows. This is when you will need a proper way to manage FAQs in your WordPress site. In this article, we will show you how to add a frequently asked questions – FAQs section in WordPress.

Basic Method

The basic method would be where you just create a page or a post in WordPress and list all the FAQs there. If you only have a handful of items, then this is the method for you. Stop reading this article now.

For those of you who want to create an elaborate FAQs section in WordPress, keep on reading.

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

Adding a FAQ Manager in WordPress

First thing you need to do is install and activate the Quick and Easy FAQs plugin. Upon installation, the plugin will add a new FAQs section in your WordPress admin menu.

You will need to visit FAQs » Add New to add your first frequently asked question. The FAQ editor looks very much like post editor.

Add the question in the title field and answer in the post edit area. On your right hand column, you will notice the FAQ Groups box. These groups are like categories in WordPress posts. You can use groups to sort questions into topics or sections.

Once you are done, click on the publish button, and repeat the process for all other frequently asked questions you want to add.

After you have a few FAQs, it is time to display them on your website.

Displaying FAQs on Your WordPress Site

You can easily display FAQs using the shortcode in a new page titled frequently asked questions, or you can add it to any WordPress post or page. Quick and Easy FAQs plugin comes with multiple display options.

Display FAQs in a List Style

This option displays FAQs in a plain list where questions are listed at the top and users can scroll up and down on the page by clicking on a question to see its answer below.

Shortcode: [faqs]

۲٫ Display FAQs in Toggle or Accordian

This option allows you to display FAQs in jQuery Toggle or Accordian style. A question will expand when a user clicks on it.

Shortcode: [faqs style=”toggle”]

Take a look at the plugin’s website for a full list of shortcode parameters.

Changing The Appearance of FAQs

The plugin relies on your theme’s colors and fonts to display the basic FAQs list. You can change its display in your theme’s stylesheet using CSS.

However if you are unfamiliar with the CSS, then you can use a plugin like CSS Hero to change any style in your WordPress theme.

This plugin uses a built-in stylesheet to control the appearance of FAQs in toggle style. It also provides an easy user interface to change colors of your FAQs. Simply go to Plugins » Quick and Easy FAQs to change the default colors.

First you need to select custom colors for ‘FAQs toggle colors’ option. After that you can simply choose the colors you want to use for each item.

Don’t forget to click on the save changes button to store your settings.

Change Display Order for FAQs

By default, the plugin shows the most recent question on top. Here is how you can change the FAQ display order and rearrange questions in anyway you want.

First thing you need to do is install and activate Post Types Order plugin. Upon activation, go to Settings » Post Types Order page.

First you need to select show next to FAQ and then select administrator next to the option ‘Minimum Level to use this plugin’.

Click on the save changes button to store your settings.

Now you need to visit FAQs » Re-Order page. Simply drag and drop FAQ titles to rearrange them in the order you want to display them.

Don’t forget to click on the update button to store your settings. That’s all, you can now visit your FAQs page to see your FAQs in the new order.

We hope this article helped you add a frequently asked questions (FAQs) section in WordPress. You may also want to see our tutorial on how to add rotating testimonials in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

]]>
http://wiki.shopingserver.com/how-to-add-a-frequently-asked-questions-faqs-section-in-wordpress-2/feed/ 0