Linux Command Line Mastery · درس

تحرير التدفقات على نطاق واسع باستخدام sed وtr

طبّق تحويلات مدعومة بالتعابير النمطية عبر التدفقات باستخدام استبدال sed، وترجم الأحرف أو احذفها باستخدام tr.

الدرس 4 من 413 خطوة

تحرير التدفقات على نطاق واسع باستخدام sed وtr درس مجاني في Linux Command Line Mastery على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Command Line Mastery، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

From Matching to Transforming

You have mastered regex matching with grep and find. The natural next step is transforming the text you match. sed and tr turn your regex skills into edits.

sed Substitution Basics

The s/pattern/replacement/ command replaces the first match per line. Add g for all matches.

echo 'cat cat cat' | sed 's/cat/dog/g'

Using Regex in sed

sed -E enables extended regex so you can use +, ?, and groups without backslashes.

echo 'a123b' | sed -E 's/[0-9]+/#/'

Capture Groups and Backreferences

Parentheses capture parts of the match; \1, \2 reuse them in the replacement. Here we swap two words.

echo 'John Smith' | sed -E 's/(\w+) (\w+)/\2 \1/'

Anchoring Substitutions

Use ^ and $ to act only at the start or end of a line, e.g. prefixing every line.

printf 'one\ntwo\n' | sed 's/^/> /'

Deleting and Selecting Lines

sed can target lines by pattern: /regex/d deletes matching lines, while -n '/regex/p' prints only matches.

printf 'keep\ndrop me\nkeep\n' | sed '/drop/d'

In-Place Editing

sed -i edits a file directly. Always keep a backup with -i.bak until you trust the command.

sed -i.bak 's/localhost/127.0.0.1/g' config.conf

Meet tr

tr translates or deletes characters (not regex). It reads stdin only. Here we uppercase text.

echo 'hello' | tr 'a-z' 'A-Z'

Deleting and Squeezing

tr -d removes characters and tr -s squeezes repeats into one, great for cleaning whitespace.

echo 'a   b    c' | tr -s ' '

Combining sed and tr

Chain them: normalize a CSV by converting commas to newlines and stripping carriage returns.

echo 'a,b,c' | tr ',' '\n' | sed 's/^/item: /'

When to Use Which

Reach for sed when you need patterns and line logic; reach for tr for fast single-character translations and deletions.

Quick Check

You want to replace every occurrence of a word on each line with sed. What must you add?

Recap

You can now transform streams with regex:

  • sed 's///g' substitutes; -E enables extended regex; \1 reuses captures
  • /re/d and -n '/re/p' select lines
  • sed -i.bak edits files safely
  • tr translates, deletes (-d), and squeezes (-s) characters
البدء مجانًا

تعلم Linux Command Line Mastery مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
12
الدروس
48

الأسئلة الشائعة

هل درس «تحرير التدفقات على نطاق واسع باستخدام sed وtr» مجاني؟

نعم — نص درس «تحرير التدفقات على نطاق واسع باستخدام sed وtr» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Command Line Mastery، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Command Line Mastery 4 دروس في المجموع.

ماذا ستتعلم في «تحرير التدفقات على نطاق واسع باستخدام sed وtr»؟

طبّق تحويلات مدعومة بالتعابير النمطية عبر التدفقات باستخدام استبدال sed، وترجم الأحرف أو احذفها باستخدام tr. تتمرن على Linux Command Line Mastery مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Linux Command Line Mastery؟

لا تُشترط خبرة سابقة. Linux Command Line Mastery على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تحرير التدفقات على نطاق واسع باستخدام sed وtr»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Linux Command Line Mastery هذا؟

نعم. كل درس في Linux Command Line Mastery يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. إتقان التعابير النمطية (Regex)
  2. أنماط متقدمة في `grep` و`find`
  3. استخدام `xargs` لربط الأوامر
  4. تحرير التدفقات على نطاق واسع باستخدام sed وtr
← العودة إلى Linux Command Line Mastery