Tutorial by Examples: by

while IFS= read -r line;do echo "**$line**" done < <(ping google.com) or with a pipe: ping google.com | while IFS= read -r line;do echo "**$line**" done
Let's assume that the field separator is : (colon) in the file file. while IFS= read -d : -r field || [ -n "$field" ]; do echo "$field" done <file For a content: first : se con d: Thi rd: Fourth The output is: **first ** ** se con d** ** Thi ...
Let's assume that the field separator is : var='line: 1 line: 2 line3' while IFS= read -d : -r field || [ -n "$field" ]; do echo "-$field-" done <<< "$var" Output: -line- - 1 line- - 2 line3 -
Let's assume that the field separator is : while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**" done < <(ping google.com) Or with a pipe: ping google.com | while IFS= read -d : -r field || [ -n "$field" ];do echo "**$field**&q...
We can just do simple replacement of separators from space to new line, as following example. echo $sentence | tr " " "\n" It'll split the value of the variable sentence and show it line by line respectively.
$sku = 'some-sku'; $productId = Mage::getModel('catalog/product')->getIdBySku($sku); if($productId){ //sku exists }
In order to avoid a divide by zero with a numberSet (what you get after a reduction like avg()) you can short-circuit the logic: $five = min(q("sum:rate{counter,,1}:haproxy.frontend.hrsp{}{status_code=5xx}", "1h", "")) $two = avg(q("sum:rate{counter,,1}:haproxy.f...
With series operations, things are dropped from the left side if there is no corresponding timestamp/datapoint in the right side. You can mix this with the dropbool function to avoid divide by zero: $five = q("sum:rate{counter,,1}:haproxy.frontend.hrsp{}{status_code=5xx}", "1h",...
Let's say we have a table team_person as below: +======+===========+ | team | person | +======+===========+ | A | John | +------+-----------+ | B | Smith | +------+-----------+ | A | Walter | +------+-----------+ | A | Louis | +------+-----------+ | C | ...
The ROLLUP operator is useful in generating reports that contain subtotals and totals. CUBE generates a result set that shows aggregates for all combinations of values in the selected columns. ROLLUP generates a result set that shows aggregates for a hierarchy of values in the selected col...
A common problem that leads to an inefficient query goes something like this: SELECT ... FROM a JOIN b ON ... WHERE ... GROUP BY a.id First, the JOIN expands the number of rows; then the GROUP BY whittles it back down the the number of rows in a. There may not be any good c...
NSLog is good, but you can also log by appending to a file instead, using code like: NSFileHandle* fh = [NSFileHandle fileHandleForWritingAtPath:path]; if ( !fh ) { [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil]; fh = [NSFileHandle fileHandleForWriting...
You can use a filter to log only messages "lower" than e.g. ERROR level. But the filter is not supported by PropertyConfigurator. So you must change to XML config to use it. See log4j-Wiki about filters. Example "specific level" <appender name="info-out" class=&quo...
TextViewPlus.java: public class TextViewPlus extends TextView { private static final String TAG = "TextView"; public TextViewPlus(Context context) { super(context); } public TextViewPlus(Context context, AttributeSet attrs) { super(context, attrs)...
Tags make it particularly easy to locate specific game objects. We can look for a single game object, or look for multiple. Finding a Single GameObject We can use the static function GameObject.FindGameObjectWithTag(string tag) to look for individual game objects. It is important to note that, i...
To install Cucumber for use with Ruby simply use the command gem install cucumber Alternatively, if you are using bundler, you can add the following line to your Gemfile gem 'cucumber' And then run bundler bundle install [I think this belongs in its own topic, Installation. I created tha...
You can re-throw error that you catch in CATCH block using TRHOW statement: DECLARE @msg nvarchar(50) = 'Here is a problem! Area: ''%s'' Line:''%i''' BEGIN TRY print 'First statement'; RAISERROR(@msg, 11, 1, 'TRY BLOCK', 2); print 'Second statement'; END TRY BEGIN CATCH print...
Often you might need to execute an unsigned script that doesn't comply with the current execution policy. An easy way to do this is by bypassing the execution policy for that single process. Example: powershell.exe -ExecutionPolicy Bypass -File C:\MyUnsignedScript.ps1 Or you can use the shorthan...
In features/step_definitions/documentation.rb: When /^I go to the "([^"]+)" documentation$/ do |section| path_part = case section when "Documentation" "documentation" else raise "Unknown documentation section: #{section...
The following example uses expect and receive to mock an Order's call to a CreditCardService, so that the test passes only if the call is made without having to actually make it. class Order def cancel CreditCardService.instance.refund transaction_id end end describe Order do des...

Page 13 of 23