Saturday, 5 January 2013

File handling examples

  1. insert lines behind a certain line:

       

      1. sed -i '/Ini_N/ a\
      2. eee
      3. /Ini_N/ a\
      4. sss
      5. ' "Config_DPCM.ini~" 

       

       

       

       

       

  2. replacing a line including 'foo':

       

      1. sed -i 's/^.*foo.*$/another string/' myfile.txt

       

       

       

       

       

  3. replacing a line:

       

      1. sed -i "s/Ini_T=5./Ini_T=2./g" `find ./ -name Config_DPCM.ini` 

       

       

       

       

       

  4. Remove empty lines with sed

       

       

       

       

       

       

  5. find string in a certain type of files using grep
    1.  

        1. find   .    -name   "*.txt"   -print

         

    2.  

      1. grep -r --include=*.m "versions" ./

       

       

      name only:

       

       

  6. Compare two directories
    1. diff -r --exclude="*.yuv" ML-My-Planck MMSE-My-Planck

No comments:

Post a Comment