¢Æ grep : ÆÐÅÏÀ» ÀÌ¿ëÇÑ search => regular expressionÀ» Àß ¸¸µå´Â °ÍÀÌ ÇÊ¿äÇÏ´Ù.
grep option(s) pattern filename(s)
OS/tdir] grep -n dba /etc/group # -n : ÆÄÀÏ ¾È¿¡¼ÀÇ ÆÐÅÏÀÌ ¹ß°ßµÈ ¶óÀÎ ¹× ¶óÀÎ ¹øÈ£
OS/tdir] grep -v dba /etc/group # -v : ÆÐÅÏÀÌ ¹ß°ßµÇÁö ¾ÊÀº ¶óÀÎ
OS/tdir] grep -n dba /etc/group /etc/passwd # ÆÄÀÏÀ» ¿©·¯°³ ³ª¿...
OS/tdir] grep -i the ~/tdir/* # -i : ´ë¼Ò±¸ºÐ ¹«½Ã(ignore) => the ´ë¼Ò±¸ºÐ ¾øÀÌ
OS/tdir] grep -li the ~/tdir/* # -l : ÆÐÅÏÀÌ µé¾îÀÖ´Â ÆÄÀÏ À̸§¸¸...
OS/tdir] grep -c the ~/tdir/* # -c : ÆÐÅÏÀÌ µé¾îÀÖ´Â ¶óÀÎ ¹øÈ£¸¸...
[ÆÐÅÏÀ» Á»´õ Á¤±³ÇÏ°Ô Ç¥ÇöÇÏ·Á¸é regular expressionÀ» »ç¿ëÇØ¾ß ÇÑ´Ù]
^ : ^ÆÐÅÏ : ÆÐÅÏÀ¸·Î ½ÃÀÛÇÏ´Â ¸ðµç ¶óÀΠã±â
$ : ÆÐÅÏ$ : ÆÐÅÏÀ¸·Î ³¡³ª´Â ¸ðµç ¶óÀΠã±â
. : d... : d·Î ½ÃÀÛÇÏ´Â 4ÀÚ¸® character ã±â
* : [a-d]* : a, b, c, d·Î ½ÃÀÛÇÏ´Â character ã±â
[] : [Dd]atabase : Database ¶Ç´Â database ã±â
[^] : [^D] : D°¡ ³ªÅ¸³ªÁö ¾Ê´Â ¶óÀΠã±â
OS/tdir] grep -i ^the ~/tdir/* # the·Î ½ÃÀÛÇÏ´Â ¶óÀΠã±â
OS/tdir] grep -i meal.$ ~/tdir/* # meal.À¸·Î ³¡³ª´Â ¶óÀΠã±â
OS/tdir] grep c...d ~/tdir/* # c·Î ½ÃÀÛÇÏ°í d·Î ³¡³ª´Â 5ÀÚ¸® character ã±â
================================================================
¢Æ egrep(expression grep) : searches files for a pattern of characters
and prints all lines that contain that pattern.
OS/tdir] egrep '(a|A)d+' /etc/passwd # ad ¶Ç´Â Ad°¡ Æ÷ÇÔµÈ ¶óÀΠã±â
OS/tdir] vi grep_test # ¾Æ·¡ ³»¿ëÀ» Ãß°¡Çϼ¼¿ä... ºÙ¿©³Ö±â... ^^
An Oracle database is a collection of data treated as a unit.
The purpose of a database is to store and retrieve related information.
A database server is the key to solving the problems of information management.
OS/tdir] egrep 'Oracle|purpose' grep_test # Oracle ¶Ç´Â purpose°¡ Æ÷ÇÔµÈ ¶óÀΠã±â
===============================================================
¢Æ sed : stream editor => fileÀ» ¿Áö ¾Ê°í data¸¦ ÆíÁýÇÏ´Â ±â´É
sed [-options] [address] command file... [>newfile]
# sed '/pattern/d' filename # file¿¡¼ ÆÐÅÏÀÌ Æ÷ÇÔµÈ ¶óÀÎÀ» Áö¿ì°í ±× °á°ú¸¦ ȸ鿡 Ç¥½Ã
# ¿øº» ÆÄÀÏ¿¡´Â ¾Æ¹«·± º¯È°¡ ¾ø´Ù.
OS/tdir] cp grep_test sed_test
OS/tdir] cat sed_test
OS/tdir] sed '/purpose/d' sed_test # purpose ¶ó´Â ´Ü¾î°¡ µé¾î°£ ¶óÀÎ »èÁ¦
# sed '#d' filename : # ¶óÀθ¸ »èÁ¦
# sed '$d' filename : ¸¶Áö¸· ¶óÀÎ »èÁ¦
# sed '#,$d' filename : # ¶óÀκÎÅÍ ¸¶Áö¸· ¶óÀαîÁö Áö¿ì±â
# sed '#,#d' filename : # ¶óÀκÎÅÍ # ¶óÀαîÁö Áö¿ì±â
OS/tdir] sed '1d' sed_test # 1 ¶óÀθ¸ »èÁ¦
OS/tdir] sed '$d' sed_test # ¸¶Áö¸· ¶óÀθ¸ »èÁ¦
OS/tdir] sed '/purpose/d' sed_test > set_out # sed ó¸® °á°ú¸¦ sed_out À¸·Î ÀúÀå
OS/tdir] cat set_out
OS/tdir] sed '/purpose/p' sed_test # ÆÐÅÏÀÌ Æ÷ÇÔµÈ ¶óÀÎÀÌ µÎ¹ø Ãâ·Â(print)µÈ´Ù.
OS/tdir] sed -n '/purpose/p' sed_test # ÆÐÅÏÀÌ Æ÷ÇÔµÈ ¶óÀθ¸ Ãâ·ÂµÈ´Ù.
OS/tdir] sed 's/$/ Oracle/' sed_test # °¢ ¶óÀÎÀÇ ¸¶Áö¸·¿¡ ¿øÇÏ´Â ±ÛÀÚ Ãß°¡
OS/tdir] sed 's/ */#/g' sed_test # space¸¦ ã¾Æ¼ #±âÈ£·Î º¯È¯ÇÑ´Ù.
OS/tdir] sed 's/ */-/g' sed_test # space¸¦ ã¾Æ¼ -±âÈ£·Î º¯È¯ÇÑ´Ù.
# * ±âÈ£ ¾Õ¿¡ space°¡ µÎ°³¶ó´Â Á¡¿¡ À¯ÀÇ
OS/tdir] # Çѹø¿¡ ¿©·¯ °¡Áö ÆíÁý ¼öÇà
OS/tdir] sed -e 's/database/DATABASE/g' -e 's/information/INFORMATION/g' sed_test
===============================================================
¢Æ awk : ÆÐÅÏ °Ë»ö°ú 󸮸¦ À§ÇÑ ¾ð¾î
=> ¸í·É¾îÀÇ À̸§Àº °³¹ßÀÚÀÎ Alfred V. Aho, Peter J. Weinberger, Brian W. Kernighan 3ÀÎÀÇ
¸Ó¸®±ÛÀÚ¸¦ »ç¿ëÇؼ ¸¸µç °ÍÀÌ´Ù.
awk '{ action}' filename
OS/tdir] ls -l | awk '{print $0}' # Àüü Çʵ尡 ¸ðµÎ ³ªÅ¸³ªµµ·Ï...
drwxr-xr-x 2 prof9i4 dba 512 4¿ù 25ÀÏ 15:44 a_dir
drwxr-xr-x 2 prof9i4 dba 512 4¿ù 18ÀÏ 23:53 b_dir
$1 $2 $3 $4 $5 $6 $7 $8 $9
$0
OS/tdir] ls -l | awk '{print $1}' # 1¹ø Çʵ常 ³ªÅ¸µµ·Ï...
OS/tdir] ls -l | awk '{print $1, $9}' # 1¹ø°ú 9¹ø Çʵ常 ³ªÅ¸³ªµµ·Ï...
OS/tdir] ls -l | awk '{print $3 "\t" $4 "\t" $9}' # Tab Å°°¡ Àû¿ëµÈ °á°ú...
OS/tdir] ls -lt | awk '{print $9, "is using", $5, "bytes"}' # text Ãß°¡
OS/tdir] ls -lt | awk '$5 <= 200 {print $0}' # 5¹ø Çʵ尡 200 ÀÌÇÏÀÏ °æ¿ì Ãâ·Â