From 7692dad08f7a3f092f82725de49a56a70a27e7de Mon Sep 17 00:00:00 2001 From: Divyanshi_Singh_Bora Date: Mon, 19 Jun 2023 23:35:58 +0530 Subject: [PATCH] fixed error #47 --- shell/basic.sh | 14 +++++++------- shell/{ => data}/grep_example.txt | 0 shell/{examples => data}/one.txt | 0 shell/{examples => data}/three.txt | 0 shell/{examples => data}/two.txt | 0 shell/examples/file_list.txt | 3 --- shell/examples/list.sh | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) rename shell/{ => data}/grep_example.txt (100%) rename shell/{examples => data}/one.txt (100%) rename shell/{examples => data}/three.txt (100%) rename shell/{examples => data}/two.txt (100%) delete mode 100644 shell/examples/file_list.txt mode change 100644 => 100755 shell/examples/list.sh diff --git a/shell/basic.sh b/shell/basic.sh index 4f87402..525d6cf 100755 --- a/shell/basic.sh +++ b/shell/basic.sh @@ -55,11 +55,11 @@ esac # TODO: Add grep # grep_example.txt is an example file you can create your own file and give its name instead of grep_example.txt to search in that file. -grep "grep" grep_example.txt # change the keyword inside the bracket to search for different words it will print the whole line if the given keyword is in that line. -grep --color "to" grep_example.txt # it will print the line which have "to" keyword in them, and --color is used to highlite the text. -grep -i "it" grep_example.txt # -i will Ignore case sensitivity -grep -c "the" grep_example.txt # -c will count the number of occurrences of the given string in the text. -grep -v "the" grep_example.txt # it will print all the lines which DO NOT have the given string. +grep "grep" data/grep_example.txt # change the keyword inside the bracket to search for different words it will print the whole line if the given keyword is in that line. +grep --color "to" data/grep_example.txt # it will print the line which have "to" keyword in them, and --color is used to highlite the text. +grep -i "it" data/grep_example.txt # -i will Ignore case sensitivity +grep -c "the" data/grep_example.txt # -c will count the number of occurrences of the given string in the text. +grep -v "the" data/grep_example.txt # it will print all the lines which DO NOT have the given string. # REGEX in grep # ^ Matches characters at the beginning of a line @@ -68,8 +68,8 @@ grep -v "the" grep_example.txt # it will print all the lines which DO NOT have # [a-z] Matches any characters between A and Z # [^ ..] Matches anything apart from what is contained in the brackets -grep ^T grep_example.txt # lines starting with T. -grep t$ grep_example.txt # To display lines that end with the letter ‘t’ run +grep ^T data/grep_example.txt # lines starting with T. +grep t$ data/grep_example.txt # To display lines that end with the letter ‘t’ run grep --help # Getting help with more Grep options diff --git a/shell/grep_example.txt b/shell/data/grep_example.txt similarity index 100% rename from shell/grep_example.txt rename to shell/data/grep_example.txt diff --git a/shell/examples/one.txt b/shell/data/one.txt similarity index 100% rename from shell/examples/one.txt rename to shell/data/one.txt diff --git a/shell/examples/three.txt b/shell/data/three.txt similarity index 100% rename from shell/examples/three.txt rename to shell/data/three.txt diff --git a/shell/examples/two.txt b/shell/data/two.txt similarity index 100% rename from shell/examples/two.txt rename to shell/data/two.txt diff --git a/shell/examples/file_list.txt b/shell/examples/file_list.txt deleted file mode 100644 index 84cfe9b..0000000 --- a/shell/examples/file_list.txt +++ /dev/null @@ -1,3 +0,0 @@ -one.txt -three.txt -two.txt diff --git a/shell/examples/list.sh b/shell/examples/list.sh old mode 100644 new mode 100755 index d9b3bfd..259ee98 --- a/shell/examples/list.sh +++ b/shell/examples/list.sh @@ -5,7 +5,7 @@ output_file="file_list.txt" #Then, we use the ls command with the *.txt pattern to list all .txt files in the current directory. The > operator redirects the output of the ls command to the specified output file. -ls *.txt > "$output_file" +ls ../data/*.txt > "$output_file" # Finally, we display a message indicating the completion of the task, specifying the name of the output file. echo "List of .txt files has been saved to $output_file"