Suppose you have a file that have pipe ("|") separated values.
122344|093462|45836
472391|093742|23444
If you want to split column 2 values, you can use the following command to get second column values easily.
cat log.txt | awk -F"|" '{print $2}'>second_column_log.txt
This will create a file called "second_column_log.txt" that contains column two values.
093462
093742
Wednesday, May 28, 2014
Check file differences in Linux
Following Linux command can be used to check two file line differences.
Before using the command you must sort the file using sort Linux command.
1.) sort err_file_1.txt > sorted_file_1.txt
2.) sdiff err_file_1.txt err_file_2.txt
Output will be shown in Linux terminal. You can write output to file using following command.
1.) sdiff err_file_1.txt err_file_2.txt >output.txt
Before using the command you must sort the file using sort Linux command.
1.) sort err_file_1.txt > sorted_file_1.txt
2.) sdiff err_file_1.txt err_file_2.txt
Output will be shown in Linux terminal. You can write output to file using following command.
1.) sdiff err_file_1.txt err_file_2.txt >output.txt
Thursday, March 20, 2014
HTTP GET/POST Example
Following example can be used to send HTTP GET or POST request to web server using JAVA application.
// HTTP GET request
private void sendGet() throws Exception {
String url = "http://seguide.blogspot.com";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.addHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(request);
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
// HTTP POST request
private void sendPost() throws Exception {
String url = "http://seguide.blogspot.com";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
List urlParameters = new ArrayList();
urlParameters.add(new BasicNameValuePair("name", "sujith"));
urlParameters.add(new BasicNameValuePair("pass", "abc123"));
urlParameters.add(new BasicNameValuePair("param1", "param1"));
urlParameters.add(new BasicNameValuePair("param2", "param2"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
// HTTP GET request
private void sendGet() throws Exception {
String url = "http://seguide.blogspot.com";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
request.addHeader("User-Agent", USER_AGENT);
HttpResponse response = client.execute(request);
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
// HTTP POST request
private void sendPost() throws Exception {
String url = "http://seguide.blogspot.com";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("User-Agent", USER_AGENT);
List
urlParameters.add(new BasicNameValuePair("name", "sujith"));
urlParameters.add(new BasicNameValuePair("pass", "abc123"));
urlParameters.add(new BasicNameValuePair("param1", "param1"));
urlParameters.add(new BasicNameValuePair("param2", "param2"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
Wednesday, March 19, 2014
Change permission for user in Linux
Following set of commands can be used to change the permission of a user.
Change directory
Change directory
sujithde@ewaps1:~> cd
delight/
Change permission for user oracle
sujithde@ewaps1:~/delight>
setfacl –R -m user:oracle:rwx .
Add user a mask
sujithde@ewaps1:~/delight>
setfacl –R -m mask:rwx .
Note : –R will recursively change permission for sub folders.
Wednesday, March 5, 2014
Run SQL script in Background in MySQL server
Following command can be used to run SQL script in background in MySQL server.
mysql --user=sujith --pass=123suji --database=postdb --host=localhost script_file results.out &
This will return output of script to result.out file.
Tuesday, March 4, 2014
JAVA 8 Lambda Expression
Following example explain how Lambda Expression can be implemented in JAVA 8.
interface MathOperation {
int execute(int a, int b);
}
public int calculate(int a, int b, MathOperation op) {
return op.execute(a, b);
}
public static void main(String[] args) {
Lamda lamda = new Lamda();
MathOperation addition = (a, b) -> (a + b);
MathOperation substract = (a, b) -> (a - b);
System.out.println(lamda.calculate(4, 5, addition));
System.out.println(lamda.calculate(4, 5, substract));
}
Thursday, February 20, 2014
Add words to file in linux
Following Linux commands can be used to add words to file.
1) open file in Linux vi editor
2) ESC and type following command as you referred
:/s/^/0/g
add zero(0) to in front of each line
^ defines the start of the line
:/s/$/0/g
add zero(0) to end of each line
$ defines the end of the line
:/s/718/0/g
replace "718" with zero(0)
1) open file in Linux vi editor
2) ESC and type following command as you referred
:/s/^/0/g
add zero(0) to in front of each line
^ defines the start of the line
:/s/$/0/g
add zero(0) to end of each line
$ defines the end of the line
:/s/718/0/g
replace "718" with zero(0)
Subscribe to:
Posts (Atom)