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

 

你可能感兴趣的:(File)