Hello all, I am having a problem with awk's string split function.
I have a string that has a number at the end, I am trying to remove the alpha portion of the string and just have the numeric part. Here is my code and the result:
BEGIN {
word = "$category121";
split(word, a, 121)
print... (2 Replies)
Hi
I need to check if field separator I am using in awk statement is " : ", for example:
TIME=12:59
HOUR=`echo "$TIME" | awk '{FS=":"; print $1}'`
MINUTES=`echo "$TIME" | awk '{FS=":"; print $2}'`
Is there a way to check within the above awk statement ?
Thanks for help -A (2 Replies)
Hi;
i have a file and i want to get;
- If the last word in line 14 is NOT equal to "Set."; then print 2nd, 3rd, 4th and 5th values of 3rd line.
and my code is:
nawk 'NR==14 {if ($NF!="Set.") (NR==3{print $2,$3,$4,$5}) }' file.txt
but no result?? :confused::(:confused::( (4 Replies)
In awk, how do I print all fields with a specified output field separator?
I have tried the following, which does not print the output FS:
echo a b c d | awk 'BEGIN{OFS = ";"}{print $0}' (3 Replies)
I need to set awk field separator to ";", but I need to avoid ";EXT".
so that
echo a;b;c;EXTd;e;f | awk -F";" '{print $3}'
would give "c;EXTd" (2 Replies)
Hi Experts ,
file :
- How to construct the awk filed separator so that $1, $2 $3 , can be assigned to the each "" range.
I am trying : awk -F"]" '{print $1}'
but it is printing the entire file. Not first field.
The desired output needed for first field... (9 Replies)
I can not figure out how to set the Output filed separator in awk when using printf.
Example:
cat file
some data
here_is_more information
Requested output
some------------data
her_is_more-----information
Here are some that does not work:
awk '{printf "%-15s %s\n",$1,$2}' OFS="-" file... (9 Replies)
Hello to all,
Please some help on this. I have the file in format as below.
How can I set the record separator as the string below in red
"No. Time Source Destination Protocol Length Info"
I've tried code below but it doesn't seem to... (6 Replies)
Friends have the following code that is correct.
BEGIN { num_reg = 0
suma_iva=0
}
{
num_reg++
suma_iva=suma_iva+int(substr($0, 103,9))
}
END{
printf ("%011d",suma_iva)
}
I have the following problem, I have to do just that but this time... (4 Replies)
Discussion started by: tricampeon81
4 Replies
LEARN ABOUT PHP
number_format
NUMBER_FORMAT(3) 1 NUMBER_FORMAT(3)number_format - Format a number with grouped thousandsSYNOPSIS
string number_format (float $number, [int $decimals])
DESCRIPTION
string number_format (float $number, int $decimals, string $dec_point = ".", string $thousands_sep = ",")
This function accepts either one, two, or four parameters (not three):
If only one parameter is given, $number will be formatted without decimals, but with a comma (",") between every group of thousands.
If two parameters are given, $number will be formatted with $decimals decimals with a dot (".") in front, and a comma (",") between every
group of thousands.
If all four parameters are given, $number will be formatted with $decimals decimals, $dec_point instead of a dot (".") before the decimals
and $thousands_sep instead of a comma (",") between every group of thousands.
PARAMETERS
o $number
- The number being formatted.
o $decimals
- Sets the number of decimal points.
o $dec_point
- Sets the separator for the decimal point.
o $thousands_sep
- Sets the thousands separator.
RETURN VALUES
A formatted version of $number.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.4.0 | |
| | |
| | This function now supports multiple bytes in |
| | $dec_point and $thousands_sep. Only the first |
| | byte of each separator was used in older ver- |
| | sions. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
number_format(3) Example
For instance, French notation usually use two decimals, comma (',') as decimal separator, and space (' ') as thousand separator.
This is achieved with this line :
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
SEE ALSO money_format(3), sprintf(3), printf(3), sscanf(3).
PHP Documentation Group NUMBER_FORMAT(3)