Showing posts with label echo. Show all posts
Showing posts with label echo. Show all posts

Sunday, March 17, 2013

Easy learn linux command line- Part 16

hello again, you learned how to use command line for open files in terminal in the last post. now you need to edit files!

what is your recommendation comment?
if you don't have any idea, this post is especially write for you. only persons that need to edit, compare two files with together,found differences between files, merging them, found any word and replace in the files, remove empty rows, sort content and etc.

Command Description
# cat example.txt | awk 'NR%2==1' remove all even lines from example.txt   
# echo a b c | awk '{print $1}' view the first column of a line   
# echo a b c | awk '{print $1,$3}' view the first and third column of a line   
# cat -n file1 number row of a file   
# comm -1 file1 file2 compare contents of two files by deleting only unique lines from 'file1'   
# comm -2 file1 file2 compare contents of two files by deleting only unique lines from 'file2'   
# comm -3 file1 file2 compare contents of two files by deleting only the lines that appear on both files   
# diff file1 file2 find differences between two files   
# grep Aug /var/log/messages look up words "Aug" on file '/var/log/messages'   
# grep ^Aug /var/log/messages look up words that begin with "Aug" on file '/var/log/messages'   
# grep [0-9] /var/log/messages select from file '/var/log/messages' all lines that contain numbers   
# grep Aug -R /var/log/* search string "Aug" at directory '/var/log' and below   
# paste file1 file2 merging contents of two files for columns   
# paste -d '+' file1 file2 merging contents of two files for columns with '+' delimiter on the center   
# sdiff file1 file2 find differences between two files and merge interactively alike "diff"   
# sed 's/string1/string2/g' example.txt replace "string1" with "string2" in example.txt   
# sed '/^$/d' example.txt remove all blank lines from example.txt   
# sed '/ *#/d; /^$/d' example.txt remove comments and blank lines from example.txt   
# sed -e '1d' exampe.txt eliminates the first line from file example.txt   
# sed -n '/string1/p' view only lines that contain the word "string1"   
# sed -e 's/ *$//' example.txt remove empty characters at the end of each row   
# sed -e 's/string1//g' example.txt remove only the word "string1" from text and leave intact all   
# sed -n '1,5p' example.txt print from 1th to 5th row of example.txt   
# sed -n '5p;5q' example.txt print row number 5 of example.txt   
# sed -e 's/00*/0/g' example.txt replace more zeros with a single zero   
# sort file1 file2 sort contents of two files   
# sort file1 file2 | uniq sort contents of two files omitting lines repeated   
# sort file1 file2 | uniq -u sort contents of two files by viewing only unique line   
# sort file1 file2 | uniq -d sort contents of two files by viewing only duplicate line   
# echo 'word' | tr '[:lower:]' '[:upper:]' convert from lower case in upper case   

Thursday, March 14, 2013

آموزش خط فرمان-قسمت شانزدهم

در قسمت قبلی اموزشهای خط فرمان اموختیم که چگونه یه فایل متنی را به وسیله خط فرمان بازنموده و محتویات آنرا ببینیم. اما اگر بخواهیم با استفاده از محیط ترمینال مقداری دستکاری در فایل های متنی باز شده بدهیم، دستورات خط فرمان چگونه خواهد بود؟

در این آموزش سعی نموده ایم نحوه ویرایش فایل های متنی را به وسیله خط فرمان لینوکس آموزش دهیم. اهم این دستورات عبارتند از:

  • مقایسه محتویات فایل ها با یکدیگر
  • نمایش تفاوت های دو فایل با یکدیگر
  • جستجوی عبارت های مشخص شده در متن
  • ادغام محتویات دو فایل مختلف با یکدیگر
  • حذف خطوط سفید در فایل
  • نمایش سطرهای دلخواه
  • تبدیل حروف کوچک به بزرگ و برعکس 

دستور توضیح
# cat example.txt | awk 'NR%2==1' تمام خطوط زوج را از example.txt حذف كن   
# echo a b c | awk '{print $1}' اولين ستون يك خط را نمايش بده   
# echo a b c | awk '{print $1,$3}' اولين و سومين ستون يك خط را نمايش بده   
# cat -n file1 نمایش سطرهای فایل با شماره   
# comm -1 file1 file2 مقايسه‌ي محتويات دو فايل كه فقط خطوط خاص را از 'file1' حذف مي‌كند   
# comm -2 file1 file2 مقايسه‌ي محتويات دو فايل كه فقط خطوط خاص را از 'file2' حذف مي‌كند   
# comm -3 file1 file2 مقايسه‌ي محتويات دو فايل كه فقط خطوط خاص را كه در دو فايل آمده را حذف مي‌كند   
# diff file1 file2 تفاوت بين دو فايل را نمايان مي‌كند   
# grep Aug /var/log/messages در فايل '/var/log/messages' كلمه‌ي "Aug" را پيدا كن  
# grep ^Aug /var/log/messages در فايل '/var/log/messages' كلمه‌ هايي را كه با "Aug" شروع مي‌شوند پيدا كن   
# grep [0-9] /var/log/messages از فايل '/var/log/messages' تمام خطوطي را كه شامل اعداد هستن نمايش بده   
# grep Aug -R /var/log/* در شاخه‌ي '/var/log' و زير شاخه‌ها كلمه‌ي "Aug" را جستجو كن   
# paste file1 file2 محتويات دو فايل را با ستون با هم ادغام كن   
# paste -d '+' file1 file2 پيوستن محتويات دو فايل براي دو ستون با استفاده از '+' به عنوان تمييز دهنده در وسط   
# sdiff file1 file2 تفاوت بين دو فايل را پيدا كن و به صورت محاوره‌اي با هم ادغام كن   
# sed 's/string1/string2/g' example.txt در فايل example.txt عبارت "string1" را با "string2" جابجا كن   
# sed '/^$/d' example.txt تمام خطوط سفيد را از فايل example.txt پاك كن   
# sed '/ *#/d; /^$/d' example.txt تمام خطوط سفيد و comment ها را از فايل example.txt پاك كن   
# sed -e '1d' exampe.txt خط اول را از فايل example.txt پاك كن   
# sed -n '/string1/p' خطوطي را نمايش بده كه شامل كمله‌ي "string1" باشد   
# sed -e 's/ *$//' example.txt كاركتر خالي در آخر هر سطر را پاك كن   
# sed -e 's/string1//g' example.txt فقط كلمه‌ي "string1" را حذف كن و بقيه را تغيير نده   
# sed -n '1,5p' example.txt سطر اول تا پنجم را از example.txt نمايش بده   
# sed -n '5p;5q' example.txt سطر پنجم را از example.txt نمايش بده   
# sed -e 's/00*/0/g' example.txt صفرهاي متعدد را با يك صفر تعويض كن   
# sort file1 file2 محتوييات دو فايل را به ترتيب كن   
# sort file1 file2 | uniq محتوييات دو فايل را به ترتيب كن و خطوط تكراري را حذف كن   
# sort file1 file2 | uniq -u محتوييات دو فايل را به ترتيب كن و خطوط تكراري نمايش بده   
# sort file1 file2 | uniq -d محتوييات دو فايل را به ترتيب كن و خطوطي را كه دو بار تكرار شده‌اند را نمايش بده   
# echo 'word' | tr '[:lower:]' '[:upper:]' حروف كوچك را به بزرگ تبديل كن