syntax: wc filename
WC command will display the total number of lines, words and characters from file.
Example: $ wc filename
2 30 100 filename
First column - Total number of lines (2 lines in example file)
Second column - number of words (30 words in example file)
Third column - number of characters (100 characters in example file)
To get only line count from file
$ wc -l filename
2 filename
To get only word count from file
$ wc -w filename
30 filename
To get only character count from file
$ wc -c filename
100 filename
Friday, October 9, 2015
Display last few lines from file in unix/linux using tail command
$ tail file.txt
It will display last 10 lines from file.txt
$ tail file.txt -n 100
It will display last 100 lines from file.txt
It will display last 10 lines from file.txt
$ tail file.txt -n 100
It will display last 100 lines from file.txt
Display first/top few lines from file in unix/linux
head -lines filename
Example: $ head -3 file.txt
It will display first 3 lines form file.txt. Here lines is an optional parameter. If you don't specify lines it will display 10 lines by default.
Example: $ head file.txt
It will display first 10 lines from file.txt
Example: $ head -3 file.txt
It will display first 3 lines form file.txt. Here lines is an optional parameter. If you don't specify lines it will display 10 lines by default.
Example: $ head file.txt
It will display first 10 lines from file.txt
Thursday, October 8, 2015
Last reboot time in Linux/Unix server
$ last reboot
The above command will display last 2 reboot time
$ last reboot
It will display last system reboot time
$ who -b
Result: system boot 2015-02-22 04:40
It will display the date and time of last reboot
$ uptime
It will also show the total time since the last reboot
The above command will display last 2 reboot time
$ last reboot
It will display last system reboot time
$ who -b
Result: system boot 2015-02-22 04:40
It will display the date and time of last reboot
$ uptime
It will also show the total time since the last reboot
Friday, January 2, 2015
Running Total in Oracle SQL query
Here is the sql query to do the running total for salary column from employee table
--Running Total Salary
SELECT
EMPLOYEE_ID,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (ORDER BY FIRST_NAME
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) Running_Total
FROM
EMPLOYEES
ORDER BY
FIRST_NAME
--Running Total Salary by department
SELECT
DEPARTMENT_ID,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENT_ID
ORDER BY DEPARTMENT_ID, FIRST_NAME) RUNNIG_TOTAL_BY_DEPT
FROM
EMPLOYEES
--Running Total Salary by department name
SELECT
DEPARTMENT_NAME,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENT_NAME
ORDER BY DEPARTMENT_NAME, FIRST_NAME) RUNNIG_TOTAL_BY_DEPT
FROM
EMPLOYEES, DEPARTMENTS
WHERE
EMPLOYEES.DEPARTMENT_ID = DEPARTMENTS.DEPARTMENT_ID
ORDER BY
DEPARTMENT_NAME,
FIRST_NAME
--Running Total Salary
SELECT
EMPLOYEE_ID,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (ORDER BY FIRST_NAME
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) Running_Total
FROM
EMPLOYEES
ORDER BY
FIRST_NAME
--Running Total Salary by department
SELECT
DEPARTMENT_ID,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENT_ID
ORDER BY DEPARTMENT_ID, FIRST_NAME) RUNNIG_TOTAL_BY_DEPT
FROM
EMPLOYEES
--Running Total Salary by department name
SELECT
DEPARTMENT_NAME,
FIRST_NAME,
SALARY,
SUM(SALARY) OVER (PARTITION BY DEPARTMENT_NAME
ORDER BY DEPARTMENT_NAME, FIRST_NAME) RUNNIG_TOTAL_BY_DEPT
FROM
EMPLOYEES, DEPARTMENTS
WHERE
EMPLOYEES.DEPARTMENT_ID = DEPARTMENTS.DEPARTMENT_ID
ORDER BY
DEPARTMENT_NAME,
FIRST_NAME
Setting date format in Telerik RadGrid column cell
You can set the date format by using the below code snippet in ItemDataBound event in telerik radgrid control
Here is a sample c# code for MM/dd/yyyy format
protected void rgDisplay_ItemDataBound(object sender, GridItemEventArgs e)
{
string strDateFormat = "MM/dd/yyyy";
if (e.Item.ItemType == GridItemType.Item ||
e.Item.ItemType == GridItemType.AlternatingItem)
{
GridDataItem gdItem = (GridDataItem)e.Item;
DateTime result;
string dateVal = DataBinder.Eval(gdItem.DataItem, "BindDateColName").ToString();
if (DateTime.TryParse(dateVal, out result))
{
gdItem["uniqueNameDateCol"].Text = result.ToString(strDateFormat);
}
}
}
Here is a sample c# code for MM/dd/yyyy format
protected void rgDisplay_ItemDataBound(object sender, GridItemEventArgs e)
{
string strDateFormat = "MM/dd/yyyy";
if (e.Item.ItemType == GridItemType.Item ||
e.Item.ItemType == GridItemType.AlternatingItem)
{
GridDataItem gdItem = (GridDataItem)e.Item;
DateTime result;
string dateVal = DataBinder.Eval(gdItem.DataItem, "BindDateColName").ToString();
if (DateTime.TryParse(dateVal, out result))
{
gdItem["uniqueNameDateCol"].Text = result.ToString(strDateFormat);
}
}
}
Subscribe to:
Posts (Atom)