BufferedReader inFile = new BufferedReader("filename");
String line = null;
try {
while ((line=inFile.readLine())!=null) {
//do something with the line here
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
Wednesday, January 28, 2009
Tuesday, January 27, 2009
Monday, January 26, 2009
Converting a java.util.Date object into a java.sql.Date object
public class ConvertDate {
public java.sql.Date convertDate(java.util.Date date) {
return new java.sql.Date(date. getTime() );
}
}
Monday, January 19, 2009
Some basic SED commands
'sed' is the search replace command that can be used in Linux.
Here are some examples on how to use 'sed':
sed 's/ //g' - remove the spaces from the file. The 'g' indicates that the spaces should be replaced globally.
sed 's/cat/dog/g' - replace all instances of the word 'cat' with the word 'dog' in the file.
sed 's/2008-...../&,/g' - search for '2008-' followed by any 5 characters and append a ',' to the end of the string. The '&' indicates what was searched for which in this case was '2008-.....'.
All of the above examples can be used to alter a file and written to a new file e.g. cat filename | sed 's/2008/2007/g' > new_filename
Here are some examples on how to use 'sed':
sed 's/ //g' - remove the spaces from the file. The 'g' indicates that the spaces should be replaced globally.
sed 's/cat/dog/g' - replace all instances of the word 'cat' with the word 'dog' in the file.
sed 's/2008-...../&,/g' - search for '2008-' followed by any 5 characters and append a ',' to the end of the string. The '&' indicates what was searched for which in this case was '2008-.....'.
All of the above examples can be used to alter a file and written to a new file e.g. cat filename | sed 's/2008/2007/g' > new_filename
Tuesday, January 6, 2009
If .... Then in Unix Scripting
if [[ ${j}==0 ]]
then
echo "${j} is 0"
else
echo "${j} is not 0"
fi
then
echo "${j} is 0"
else
echo "${j} is not 0"
fi
Subscribe to:
Posts (Atom)