From b5cd1bcfd748330542a8f9c53a47efcfaf03a444 Mon Sep 17 00:00:00 2001 From: Maya Mizrachi Date: Sun, 9 Feb 2025 23:47:05 +0200 Subject: [PATCH] this is Maya Mizrachi assignment --- q1.sh | 16 +++++++++++++++- q2.sh | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 q2.sh diff --git a/q1.sh b/q1.sh index f7ac848..9f5934c 100644 --- a/q1.sh +++ b/q1.sh @@ -1 +1,15 @@ -This is q1 answer +#הדפיסו את מספר השורות בספר. + awk '{print NR, $0}' aliceinwonderland.txt | tail -1 | cut -f1 -d " " + + #הדפיסו את מספר המופעים של המלה Alice) עם רווח לפני ואחרי) בספר. +awk '{count += gsub(/ Alice /, "")} END {print count}' aliceinwonderland.txt + +# הדפיסו את כל המלים שחוזרות רק פעם אחת בקובץ. הגדרה: "מלה" היא מחרוזת בין רווחים +awk '{for (i=1; i<=NF; i++) print $i}' file.txt | sort | uniq -u + +# הדפיסו את 5 המלים הנפוצות ביותר בספר (ניתן להשתמש גם בפקודות שאינן awk(. +tr -c '[:alnum:]' '[\n*]' < aliceinwonderland.txt | sort | uniq -c | sort -n | ta + +# הדפיסו את האורך הממוצע של מלה בקובץ. +awk '{total_words += NF; for (i = 1; i <= NF; i++) total_length += length($i)} END {if (total_words > 0) print total_length / total_words}' aliceinwonderland.txt + diff --git a/q2.sh b/q2.sh new file mode 100644 index 0000000..8570833 --- /dev/null +++ b/q2.sh @@ -0,0 +1,15 @@ +#[200~כתבו פקודה המדפיסה את מספר השורות בהן מופיעה המלה Sherlock או Holmes. +sed -n '/Sherlock\|Holmes/p' sherlockholmes.txt | wc -l + +# כתבו פקודה המדפיסה את מספר הפעמים בהם מופיעה המלה Shelock או Holmes. +sed -n 's/.*\(Sherlock\|Holmes\).*/\1/gp' sherlockholmes.txt | wc -l + +#כתבו פקודה שמוסיפה את המחרוזת ":Hello "בתחילת כל שורה +sed 's/^/Hello /' sherlockholmes.txt + +#replace full name by my name +sed -E 's/\b[A-Z][a-zA-Z]{1,} [A-Z][a-zA-Z]{1,}\b/Maya/g' sherlockholmes.txt + +#כתבו פקודה המחליפה את כל המשפטים שבתוך סוגריים עגולים למשפטים בתוך סוגריים מרובעים. + sed -E 's/\(([^()]*)\)/[\1]/g' sherlockholmes.txt +