Sponsored Content
Top Forums Shell Programming and Scripting Script needed to align java/c/C++ code Post 302323876 by askumarece on Tuesday 9th of June 2009 08:59:46 AM
Old 06-09-2009
I just need to correct the indent of each line as per java standards....

Say for eg if have a input like below :
Code:
#######
import java.util.Date;

public class Test {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Date OldDate = new Date("04/15/2008"); 
		Date TodaysDate = new Date();
	System.out.println("TodaysDate : " + TodaysDate.getTime()); 
	long mills_per_day = 1000 * 60 * 60 * 24;
	System.out.println("mills_per_day : " + mills_per_day);
		long day_diff = ( TodaysDate.getTime() - OldDate.getTime() ) / mills_per_day; 
		System.out.println("day_diff : " + day_diff);
String b2bi_errors1 = "errrrrrrrrrr";
		String clin = "2342345";
		String b2bi_errors = getQuotedString(b2bi_errors1 
			+ "; IOMSales400: CLIN "
		+ clin
			+ ": Transport CLINs require at least 2 " 
				+ "locations for proper pricing.");
//String ret = getDoubleQuotedString("String");
		System.out.println("Return String : " + b2bi_errors);
	String[] locationLabel = new String[1];
	}

	private static String getQuotedString(String string) {
String ret = "\"" + string + "\"";
		return ret;
	}
	
}
#######################

So, my duty is to align the indent of each line... like below
Code:
###########################
import java.util.Date;


public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Date OldDate = new Date("04/15/2008"); 
		Date TodaysDate = new Date();
		System.out.println("TodaysDate : " + TodaysDate.getTime()); 
		long mills_per_day = 1000 * 60 * 60 * 24;
		System.out.println("mills_per_day : " + mills_per_day);
		long day_diff = ( TodaysDate.getTime() - OldDate.getTime() ) / mills_per_day; 
		System.out.println("day_diff : " + day_diff);
		String b2bi_errors1 = "errrrrrrrrrr";
		String clin = "2342345";
		String b2bi_errors = getQuotedString(b2bi_errors1 
				+ "; IOMSales400: CLIN "
				+ clin
				+ ": Transport CLINs require at least 2 " 
				+ "locations for proper pricing.");
//		String ret = getDoubleQuotedString("String");
		System.out.println("Return String : " + b2bi_errors);
		String[] locationLabel = new String[1];
	}

	private static String getQuotedString(String string) {
		String ret = "\"" + string + "\"";
		return ret;
	}
	
}
#######################


Last edited by Franklin52; 06-09-2009 at 10:03 AM.. Reason: please add code tags
 

9 More Discussions You Might Find Interesting

1. Programming

can i have an optimal solution for this java code ? Facing Java heap space problem even at 3GB heaps

My desired output is run: for this 1 for this 2 for this 3 for this 4 for this 5 for this 1,2 1->2 for this 2,3 2->3 for this 3,4 3->4 for this 4,5 4->5 for this 1,2,3 1->2,3 (2 Replies)
Discussion started by: vaibhavkorde
2 Replies

2. Programming

date change shell script in java code

hi, I have a code to connect to a remote Linux server through windows using SSH, with host-name, username and password built in the code. I want to add a shell script in the code which should execute automatically without any user intervention. (as u know that date change requires you/us to be... (0 Replies)
Discussion started by: tarkan
0 Replies

3. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

4. Programming

Script Shell in java code

Hello, This is my script shell: echo Mon premier script echo Liste des fichiers : ls -la exit 0 This is my code java: public class test { public static void main(String args) { try { Process process = Runtime.getRuntime().exec("sh script1.sh"); } catch... (2 Replies)
Discussion started by: chercheur857
2 Replies

5. Shell Programming and Scripting

Code java in script shell

Hello; Is it possible to insert Java code in a shell script, if so how please? Thank you (0 Replies)
Discussion started by: chercheur857
0 Replies

6. Programming

Script shell in java code

Hello, Please i want to insert this code in a java program because i need to call a java function inside the while: Please how can i do? thank you so much (9 Replies)
Discussion started by: chercheur857
9 Replies

7. UNIX for Dummies Questions & Answers

Script Shell in java code

Hello, I try to run a script shell from a java program: but it runs only if i do :chmod 777 myShellScript in the terminal Please how can i insert chmod 777 in my java code without going through the terminal? Thank you (1 Reply)
Discussion started by: chercheur857
1 Replies

8. Shell Programming and Scripting

Shell script with Java code in Cron

Dear All, I have a shell script which has JAVA code inside it runs perfectly on command line. But while I set it on cron, all rest of the script runs but Java code doesnt. java -cp... (3 Replies)
Discussion started by: Deei
3 Replies

9. Shell Programming and Scripting

Passing Username & password through shell script to java code

Hi, I have a shell script (script.sh) in which we are calling java code which asks for Username: Password: for authentication purpose currently we are passing the credential manually and run the script. but I am trying echo -e "user_id\npassword" | script.sh but its not... (1 Reply)
Discussion started by: rakeshtomar82
1 Replies
XtErrorMsg(3)						    XT COMPATIBILITY FUNCTIONS						     XtErrorMsg(3)

NAME
XtErrorMsg, XtSetErrorMsgHandler, XtWarningMsg, XtSetWarningMsgHandler - high-level error handlers SYNTAX
void XtErrorMsg(String name, String type, String class, String default, String *params, Cardinal *num_params); void XtSetErrorMsgHandler(XtErrorMsgHandler msg_handler); void XtSetWarningMsgHandler(XtErrorMsgHandler msg_handler); void XtWarningMsg(String name, String type, String class, String default, String *params, Cardinal *num_params); ARGUMENTS
class Specifies the resource class. default Specifies the default message to use. name Specifies the general kind of error. type Specifies the detailed name of the error. msg_handler Specifies the new fatal error procedure, which should not return or the nonfatal error procedure, which usually returns. num_params Specifies the number of values in the parameter list. params Specifies a pointer to a list of values to be stored in the message. DESCRIPTION
The XtErrorMsg function has been superceded by XtAppErrorMsg. The XtSetErrorMsgHandler function has been superceded by XtAppSetErrorMsgHandler. The XtSetWarningMsgHandler function has been superceded by XtAppSetWarningMsgHandler. The XtWarningMsg function has been superceded by XtAppWarningMsg SEE ALSO
XtAppErrorMsg(3) X Toolkit Intrinsics - C Language Interface Xlib - C Language X Interface X Version 11 libXt 1.1.4 XtErrorMsg(3)
All times are GMT -4. The time now is 01:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy