2013年9月15日星期日

grep in Linux and Unix, the difference

By grep can specify a string of text will be found out to me , and to specify the number of rows up and down but also to check out , as follows:
grep -10 '15130fe9-8514-4fdc-ab20-38746b0068ad 'server01.log> abc.xml

under Linux can run no problem, but a problem on UNIX , run ;
only under UNIX
grep '15130fe9-8514-4fdc-ab20-38746b0068ad 'server01.log> abc.xml

How would under Unix N rows up and down before the string to search out , big thank you to take them ;
------ Solution --------------- -----------------------------
unix grep on a no -A-B-C ; option do ?
------ Solution ---------------------------------------- ----
uname -a

the results posted out
------ Solution ------------------------------ --------------
man grep slowly see !
------ Solution ---------------------------------------- ----

Well, wait till your friends.
If it is Solaris, try / usr/xpg4/bin/grep
If it is HP-UX or AIX, then do not expect to grep , and is generally used sed / awk to get.
------ Solution ---------------------------------------- ----
sed I could not really use, so try okay
sed -n '/15130fe9-8514-4fdc-ab20-38746b0068ad/=' server01.log

caught Rows
then according to the number of rows say n, you are looking after 10 lines before line 10 , so that p = n-10, 1 = n +10
sed -n "${p},${q}p server01.log"  

------ For reference only ----------------------------------- ----
previously performed under unix grep -10 '15130fe9-8514-4fdc-ab20-38746b0068ad 'server01.log> abc.xml
prompt syntax errors, terrible bar

------ For reference only ---------------------------------- -----
Linux shengchan 2.6.32-279.el6.x86_64 # 1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU / Linux
------ For reference only ------------------------------------ ---
wrong unix should stick out
------ For reference only ---------------------- -----------------

Well, wait till your friends.   
If it is Solaris, try / usr/xpg4/bin/grep   
If it is HP-UX or AIX, then do not expect to grep , and is generally used sed / awk to get.  
Masters afternoon a little busy , thank you for your reply, thank you ;
------ For reference only ------------------------ ---------------
Thank Masters

没有评论:

发表评论