zoukankan      html  css  js  c++  java
  • grep piple & file

    please notice that the string appended to grep command should be piple or file name, should not be just a string.

    of course you can exploit the temp file for your resolution as possible as you can.

    dos copy --> right click

    Below is an example:

     1 #!/bin/bash
     2 
     3 #----------------------------------------------------------------
     4 # This script is used to extract the methods of the java class
     5 #-----------------------------------------------------------------
     6 cat java.java | while read line
     7 do
     8  #echo $line > temp.txt
     9  #grep "public class" temp.txt >> result.txt
    10  #grep "public.*{" temp.txt >> result.txt
    11  #grep "private.*{" temp.txt >> result.txt
    12  #rm temp.txt
    13  
    14  if [[ -n `echo $line | grep "public class"` ]]
    15  then 
    16      echo $line >> result.txt
    17  elif [[ -n `echo $line | grep "public.*{"` ]]
    18  then
    19      echo $line >> result.txt
    20  elif [[ -n `echo $line | grep "private.*{"` ]]
    21  then
    22   echo $line >> result.txt
    23  else
    24   echo hello
    25   continue
    26  fi
    27 done
  • 相关阅读:
    Mac php使用gd库出错 Call to undefined function imagettftext()
    centos 使用 locate
    Mac HomeBrew 安装 mysql
    zsh 命令提示符 PROMPT
    新的开始
    Java 面试题分析
    Java NIO Show All Files
    正确使用 Volatile 变量
    面试题整理 2017
    有10阶梯, 每次走1,2 or 3 阶,有多少种方式???
  • 原文地址:https://www.cnblogs.com/kelin1314/p/1964056.html
Copyright © 2011-2022 走看看