choose language

Custom Search

Saturday, 19 February 2011

unix tips, convert man pages to text files, linux tips, solaris tips, How to replace text in multiple files, execute commands at specified times

 Hi
Below some important general unix tips:
  • How to run a command to a set of files (The while read command can handle names with spaces but you need to quote the variable after):
    [unix]$ for i in `ls *mp3`; do cp $i $i.bak; done
    [unix]$ ls *mp3 | while read i; do cp "$i" "$i with more spaces"; done
  • How to rename part of a file:
    [unix]$ echo filename | sed 's/file/another/'
  • How to replace text in multiple files:
    [unix]$ sed -e 's/oldtext/newtext/' -i file1 file2 file3 ...
  • How to delete lines matching a pattern in some files:
    [unix]$ sed -e '/pattern/ d' -i file1 file2 file3 ...
  • How to change all letters to lowercase:
    [unix]$ echo FilENamE | tr A-Z a-z
  • A good way to change all filenames in a directory to lowercase:
    This handles a colored ls (hence the quotes around ls, but you can use any file list output, i.e. find) and names with spaces (hence the while read and not the for).
    [unix]$ "ls" | while read name; do mv "$name" "`echo $name | tr A-Z a-z`"; done
  • How to convert man pages to text files:
    [unix]$ man man | col -b
  • How to list all the open ports and programs:
    [linux]$ netstat -apne --inet
    [freebsd]$ sockstat
  • How to list all the open files and programs:
    [linux]$ lsof
    [freebsd]$ fstat
  • How to find information about an ip (i.e. 10.0.0.0):
    [unix]$ host 10.0.0.0
    [unix]$ dig -x 10.0.0.0
  • How to find information about an ip owner (i.e. 10.0.0.0):
    [unix]$ whois -h whois.arin.net 10.0.0.0
  • How to find out the mailserver for an ip:
    [unix]$ dig mx some.domain.name.net
  • How to generate a filename with yesterdays date (i.e. for logfiles/backups):
    [linux]$ touch logfile-`date -dyesterday '+%Y-%m-%d'`
    [freebsd]$ touch logfile-`date -v-1d '+%Y-%m-%d'`
    
    
Commands/options you should know about, read the man pages
  • tail - display the end of a file
  • head - display the beggining of a file
  • xargs - convert stdin to command line arguments
  • nmap - network scanner
  • watch (linux) - run a command periodically and watch the output
  • watch (freebsd) - monitor a tty
  • lsof - lists the open files
  • strace (linux) - trace the system calls of a program
  • truss (freebsd) - trace the system calls of a program
  • calc - command line calculator program
  • bc - another command line calculator program
  • dc - command line RPN calculator program
  • du - how much disk space is being used by something
  • df - disk free, how much free space there is
  • touch - creates an epty file or updates the timestamp on a file
  • diff - show the difference between 2 files
  • strings - show the strings in a file (useful for binaries)
  • file - tells you what type a file is
  • finger - find out information about users
  • w / who - who is currently on the machine and what are they doing
  • id - tells you who you are
  • uname - tells you basic information about the system.
  • whois - information about hosts
  • crontab - execute commands at specified times
  • last - last users to log into the system
  • mail - very basic mailer, useful for redirection
  • nice/renice - set the niceness ("priority") level of a program
  • nohup - leave a program running after logging off
  • screen - virtual terminal for leaving programs running
  • psnup - print multiple pages in one page
  • time - time the execution of a command
  • wc - word count, tells you the size in bytes, words and lines
  • which / whereis - locates commands
  • locate - locates files
  • whatis - gives brief summary of a comm
  • and
  • wget / fetch - get files off the net
  • talk - chat with other users on the system
  • write / wall - send messages to users of the system
  • zcat - cat gzipped files
  • ln - link files
  • sleep - wait a specified amount of time
  • md5sum (linux) - calculate the md5 signature of a file
  • md5 (freebsd) - calculate the md5 signature of a file
  • enscript - convert text files to ps
  • awk, sed - useful scripting programs
  • cat, echo, more/less, find, grep - you need to know these, it's not an option.

Resource: http://sluglug.ucsc.edu/~isolis/knowledge/unix-tips/

Friday, 11 February 2011

Access task manager without control-alt-delete

 Problem:
How to access task manager without control-alt-delete:

solution:

1-Option1:
 right click on an empty area of your taskbar, and clicking on "Task Manager".

2-Option2:
Use the key combination:   Ctrl+Shift+Esc


I hope this helps...

MS Excel adding problem, MS excel Summation problem

Hi and welcome to the new Tip:
Problem:
One of my friends asked me "When i tried to add numbers like 1,2 and 5,5 i get an error message and icannot do it".

Solution:

use the dot instead of the comma  . instead of ,  like this:
1.2+5.5  iinstead of 1,2 +5,5
================================================

Wrong form:













correct form:


fatal error 1603, excel error, Visual studio.net 2005 toolbox

1-Problem:
Visual Studio 2005 -- Error code 1603 for this component means "Fatal error during installation:

example error:
[08/08/07,12:28:44] Microsoft Document Explorer 2005: [2] Error code 1603 for this component means "Fatal error during installation.

solution:

according to my case: i installed previously the Visual studio 2008 and uninstalled it. when i tried to install VS2005 the error 1603 "Fatal error" appeared. i removed all related files of the previous installation using "Add/Remove programs". and then i installed it successfully.


i found alot of other solutions ,it seeems for different-but related problems-, i mentioned them below:


http://support.microsoft.com/kb/834484
http://support.microsoft.com/kb/968749

Wednesday, 12 January 2011

Windows XP System Hangs Response , explorer.exe hack

This trick is important when you don't like to reboot your computer when it hangs, you can follow these simple steps to 'reboot' your computer without 'rebooting' it.

Press CRTL + ALT + DEL

Goto the 'processes' tab and click explorer.exe once and then click 'end process'.

Now, click File > New Task and type explorer.exe

then you will  see to the normal behaviour again. except if it is a major problem that needs restart.

Saturday, 8 January 2011

how to open office 2007 files into Office 2003

how to open office 2007 files into Office 2003
 
 
TIP takem from:tricksystem.com

Today tip will help you to resolve the compatibility issues between the Office 2003 and Office 2007. Because all programs in office 2003 used the old file extensions for its different programs.  For example Word 2003 saved files with extension .doc, Excel 2003 with .xls and PowerPoint with .ppt. but on the other office 2007 used the new file extensions for its different programs.  For example Word 2007 saved files with extension .docx, Excel 2007 with .xlsx and PowerPoint with .pptx. Now the problem is that when you will try to open office 2007 files into office 2003 and you will not open the file due to compatibility issues between both office versions.  Microsoft provides a free compatibility pack to convert office 2007 documents to the office 2003 format. There are many third party free converter are available but here we are using Microsoft office compatibility pack.
Follow the given steps to download free Microsoft compatibility pack and install it.
To use this feature, you will need to be logged into your computer with administrative rights.
Visit the following link to download the Microsoft compatibility pack:

Using Loops in VBA in Microsoft Excel

taken from: exceltip.com

Why Loops?

The purpose of a loop is to get Excel to repeat a piece of code a certain number of times. How many times the code gets repeated can be specified as a fixed number (e.g. do this 10 times), or as a variable (e.g. do this for as many times as there are rows of data).
Loops can be constructed many different ways to suit different circumstances. Often the same result can be obtained in different ways to suit your personal preferences. These exercises demonstrate a selection of different ways to use loops.
There are two basic kinds of loops, both of which are demonstrated here: Do…Loop and For…Next loops. The code to be repeated is placed between the key words.
Open the workbook VBA02-Loops.xls and take a look at the four worksheets. Each contains two columns of numbers (columns A and B). The requirement is to calculate an average for the numbers in each row using a VBA macro.
Now open the Visual Basic Editor (Alt+F11) and take a look at the code in Module1.  You will see a number of different macros. In the following exercises, first run the macro then come and read the code and figure out how it did what it did.
You can run the macros either from the Visual Basic Editor by placing your cursor in the macro and pressing the F5 key, or from Excel by opening the Macros dialog box (ALT+F8) choosing the macro to run and clicking Run. It is best to run these macros from Excel so you can watch them as they work.

Exercise 1: Do… Loop Until…

The object of this macro is to run down column C as far as is necessary putting a calculation in each cell as far as is necessary.
On Sheet1 select cell C2 and run the macro Loop1.
Here's the code:
Sub Loop1()
' This loop runs until there is nothing in the next column
    Do
    ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
This macro places a formula into the active cell, and moves into the next cell down. It uses Loop Until to tell Excel to keep repeating the code until the cell in the adjacent column (column D) is empty. In other words, it will keep on repeating as long as there is something in column D.
Delete the data from cells C2:C20 and ready for the next exercise

Exercise 2: Do While… Loop

The object of this macro is to run down column C as far as is necessary putting a calculation in each cell as far as is necessary.
On Sheet1 select cell C2 and run the macro Loop2
Here's the code
Sub Loop2()
' This loop runs as long as there is something in the next column
    Do While IsEmpty(ActiveCell.Offset(0, 1)) = False
    ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
    ActiveCell.Offset(1, 0).Select
    Loop
End Sub
This macro does the same job as the last one using the same parameters but simply expressing them in a different way. Instead of repeating the code Until something occurs, it does something While something is the case. It uses Do While to tell Excel to keep repeating the code while there is something in the adjacent column as opposed to until there is nothing there. The function IsEmpty = False means "Is Not Empty".
Delete the data from cells C2:C20 and ready for the next exercise

Exercise 3: Do While Not… Loop

The object of this macro is to run down column C as far as is necessary putting a calculation in each cell as far as is necessary.
On Sheet1 select cell C2 and run the macro Loop3.
Here's the code:
Sub Loop3()
' This loop runs as long as there is something in the next column
    Do While Not IsEmpty(ActiveCell.Offset(0, 1))
    ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
    ActiveCell.Offset(1, 0).Select
    Loop
End Sub
This macro makes exactly the same decision as the last one but just expresses it in a different way. IsEmpty = False means the same as Not IsEmpty. Sometimes you can't say what you want to say one way so VBA often offers an alternative syntax.
Delete the data from cells C2:C20 and ready for the next exercise

Exercise 4: Including an IF statement

The object of this macro is as before, but without replacing any data that may already be there.
Move to Sheet2, select cell C2 and run the macro Loop4.
Here's the code:
Sub Loop4()
' This loop runs as long as there is something in the next column
' It does not calculate an average if there is already something in the cell
    Do
    If IsEmpty(ActiveCell) Then
        ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
    End If
    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
The previous macros take no account of any possible contents that might already be in the cells into which it is placing the calculations. This macro uses an IF statement that tells Excel to write the calculation only if the cell is empty. This prevents any existing data from being overwritten. The line telling Excel to move to the next cell is outside the IF statement because it has to do that anyway.

Exercise 5: Avoiding Errors

This macro takes the IF statement a stage further, and doesn't try to calculate an average of cells that are empty.
First, look at the problem. Move to Sheet3, select cell C2 and run the macro Loop4.
Note that because some of the pairs of cells in columns A and B are empty, the =AVERAGE function throws up a #DIV/0 error (the Average function adds the numbers in the cells then divides by the number of numbers - if there aren't any numbers it tries to divide by zero and you can't do that!).
Delete the contents of cells C2:C6 and C12:C20. Select cell C2 and run the macro Loop5.
Here's the code:
Sub Loop5()
' This loop runs as long as there is something in the next column
' It does not calculate an average if there is already something in the cell
' nor if there is no data to average (to avoid #DIV/0 errors).
    Do
    If IsEmpty(ActiveCell) Then
        If IsEmpty(ActiveCell.Offset(0, -1)) And IsEmpty(ActiveCell.Offset(0, -2)) Then
            ActiveCell.Value = ""
        Else
            ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
        End If
    End If
    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
Note that this time there are no error messages because Excel hasn't tried to calculate averages of numbers that aren't there.
In this macro there is a second IF statement inside the one that tells Excel to do something only if the cell is empty. This second IF statement gives excel a choice. Instead of a simple If there is an If and an Else. Here's how Excel reads its instructions…
"If the cell has already got something in, go to the next cell. But if the cell is empty, look at the corresponding cells in columns A an B and if they are both empty, write nothing (""). Otherwise, write the formula in the cell. Then move on to the next cell."

Exercise 6: For… Next Loop

If you know, or can get VBE to find out, how many times to repeat a block of code you can use a For… Next loop.
Move to Sheet4, select cell C2 and run the macro Loop6.
Here's the code:
Sub Loop6()
' This loop repeats for a fixed number of times determined by the number of rows
' in the range
    Dim i AsInteger
    For i = 1 To Selection.CurrentRegion.Rows.Count - 1
    ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
    ActiveCell.Offset(1, 0).Select
    Next i
End Sub
This macro doesn't make use of an adjacent column of cells like the previous ones have done to know when to stop looping. Instead it counts the number of rows in the current range of data and uses the For… Next method to tell Excel to loop that number of times (minus one, because when VBA counts it starts at zero).

Exercise 7: Getting the Reference From Somewhere Else

Select cell G2 and run the macro Loop7.
Here's the code:
Sub Loop7()
' This loop repeats a fixed number of times getting its reference from elsewhere
    Dim i As Integer
    Dim intRowCount As Integer
    intRowCount = Range("A1").CurrentRegion.Rows.Count - 1
    For i = 1 To intRowCount
    ActiveCell.FormulaR1C1 = "=Average(RC[-5],RC[-6])"
    ActiveCell.Offset(1, 0).Select
    Next i
End Sub
You can get the reference for the number of loops from anywhere. This macro places a set of calculations in column G for a number of times dictated by the number of rows in the block of data starting with cell A1. The For… Next statement has been simplified a bit by first declaring a variable intRowCount and filling it with the appropriate information (how many rows in the block by A1). This variable gets used in the next line instead of a long line of code. This is just another example of doing the same job a different way.
If you wanted to construct a loop that always ran a block of code a fixed number of times, you could simply use an expression like:
            For i = 1 To 23

Exercise 8: About Doing Calculations…

All the previous exercises have placed a calculation into a worksheet cell by actually writing a regular Excel function into the cell (and leaving it there) just as if you had typed it yourself. The syntax for this is:
ActiveCell.FormulaR1C1 = “TYPE YOUR FUNCTION HERE”
These macros have been using:
ActiveCell.FormulaR1C1 = “=Average(RC[-5],RC[-6])”
Because this method actually places a function into the cell rather than a value, their results will change as the cells that they refer to change, just like regular functions – because they are regular functions. The calculating gets done in Excel because all that the macro did was to write the function.
If you prefer, you can get the macro to do the calculating and just write the result into the cell. VBA has its own set of functions, but unfortunately AVERAGE isn’t one of them. However, VBA does support many of the commoner Excel functions with its WorksheetFunction method.
On Sheet1 select cell C2 and run the macro Loop1.
Take a look at the cells you just filled in. Each one contains a function, written by the macro.
Now delete the contents from the cells C2:C20, select cell C2 and run the macro Loop8.
Here’s the code:
Sub Loop8()
    Do
    ActiveCell.Value = WorksheetFunction.Average(ActiveCell.Offset(0, -1).Value, _
         ActiveCell.Offset(0, -2).Value)
    ActiveCell.Offset(1, 0).Select
    Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
Take a look at the cells you just filled in. This time there’s no function, just the value. All the calculating was done by the macro which then wrote the value into the cell.