我正在使用grep来匹配文件中的字符串.这是一个示例文件:
example one,
example two null,
example three,
example four null,
Run Code Online (Sandbox Code Playgroud)
grep -i null myfile.txt 回报
example two null,
example four null,
Run Code Online (Sandbox Code Playgroud)
如何将匹配的行与其行号一起返回,如下所示:
example two null, - Line number : 2
example four null, - Line number : 4
Total null count : 2
Run Code Online (Sandbox Code Playgroud)
我知道-c返回总匹配的行,但我不知道如何正确格式化以total null count在前面添加,我不知道如何添加行号.
我能做什么?
我想计算2小时/分钟/秒之间的差异.
我的代码在这里有点问题:
String dateStart = "11/03/14 09:29:58";
String dateStop = "11/03/14 09:33:43";
// Custom date format
SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
Date d1 = null;
Date d2 = null;
try {
d1 = format.parse(dateStart);
d2 = format.parse(dateStop);
} catch (ParseException e) {
e.printStackTrace();
}
// Get msec from each, and subtract.
long diff = d2.getTime() - d1.getTime();
long diffSeconds = diff / 1000;
long diffMinutes = diff / (60 * 1000);
long diffHours = diff …Run Code Online (Sandbox Code Playgroud) 为什么Comparable使用Java ?为什么有人会Comparable在课堂上实施?您需要实施可比较的现实生活示例是什么?
这个问题与我之前的问题有关:
我想在我的for循环中插入从0开始的计数器,到目前为止我尝试了几种组合:
<c:forEach var="tableEntity" items='${requestScope.tables}'>
<c:forEach var="rowEntity" items='${tableEntity.rows}' varStatus="count">
<c:out value="${count}" />
</c:forEach>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
<c:set var="count" value="0" scope="page" />
<c:forEach var="tableEntity" items='${requestScope.tables}'>
<c:forEach var="rowEntity" items='${tableEntity.rows}'>
<%=count++%>
<c:out value="${count}" />
</c:forEach>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
第一种方法的问题是外部循环有3个项目,内部循环有7个项目,因此对于每个外部项目,计数从0开始.第二个我得到编译错误.这基本上是我想要的:
counter = 0;
outer for loop
inner for loop
counter++;
//cout/echo/print counter value should start from 0
end inner loop
end outer loop
Run Code Online (Sandbox Code Playgroud)
我只是不完全熟悉语法.谢谢
如何创建maven pom,这将使项目可构建,我可以直接将propriatery jar包括在我的项目中,而无需从存储库中获取它们吗?有没有人这样做过?
编辑:
我不希望通过使用依赖jar构建程序集使其可运行,我希望它是可构建的.因此,任何拥有此项目的人都能够构建它,即使在任何存储库中都找不到罐子.
你好我一直在试图找出在我的应用程序中记录http请求的通用方法,到目前为止没有运气,这是我现在如何处理日志记录,即:
@RequestMapping(value="register", method = RequestMethod.POST)
@ResponseBody
public String register(@RequestParam(value="param1",required=false) String param1, @RequestParam("param2") String param2, @RequestParam("param3") String param3, HttpServletRequest request){
long start = System.currentTimeMillis();
logger.info("!--REQUEST START--!");
logger.info("Request URL: " + request.getRequestURL().toString());
List<String> requestParameterNames = Collections.list((Enumeration<String>)request.getParameterNames());
logger.info("Parameter number: " + requestParameterNames.size());
for (String parameterName : requestParameterNames){
logger.info("Parameter name: " + parameterName + " - Parameter value: " + request.getParameter(parameterName));
}
//Some processing logic, call to the various services/methods with different parameters, response is always String(Json)
String response = service.callSomeServiceMethods(param1,param2,param3);
logger.info("Response is: " …Run Code Online (Sandbox Code Playgroud) 是否可以在命令行中执行shell脚本,如下所示:
counter=`ps -ef | grep -c "myApplication"`; if [ $counter -eq 1 ] then; echo "true";
>
Run Code Online (Sandbox Code Playgroud)
以上示例不起作用我只得到>字符而不是我想要得到的结果,那就是"真实"
当我执行时,ps -ef | grep -c "myApplication我得到1输出.是否可以在脚本中从单行创建结果?谢谢
我有一些值在我的表中重复,我想只选择那些具有最新/最高日期的值,即:
ID Type Name Value Date
-- ------- ----- ------- -------------
1 "FRUIT" "APPLE" "Imported" "2011-03-19 22:08:13"
5 "FRUIT" "LEMON" "Imported" "2011-03-19 22:00:44"
22 "FRUIT" "PEACH" "Imported" "2011-03-20 11:03:13"
31 "FRUIT" "MELON" "Imported" "2011-04-28 18:42:07"
44 "FRUIT" "PEACH" "Imported" "2011-04-12 11:06:11"
98 "FRUIT" "CHERRY" "Imported" "2011-03-19 22:46:04"
211 "FRUIT" "MELON" "Imported" "2011-03-19 22:25:24"
217 "VEG" "SPINACH""Imported" "2011-03-19 22:25:24"
Run Code Online (Sandbox Code Playgroud)
我想选择这些:
ID Type Name Value Date
-- ------- ----- ------- -------------
1 "FRUIT" "APPLE" "Imported" "2011-03-19 22:08:13"
5 "FRUIT" "LEMON" "Imported" "2011-03-19 …Run Code Online (Sandbox Code Playgroud) 我正在尝试按其字段(即Person.java)对Java对象进行分组
public class Person {
String name;
String surname;
....
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我有n个 Person对象,那么让所有人将"David"命名为地图的最简单方法是Map<String, List<Person>> map;什么?
我在Google上发现了这个(但它没有编译),它似乎是我正在寻找的东西:http: //www.anzaan.com/2010/06/grouping-objects-using-objects-property/