From 36729901a8c7a214bece204b30b1e4bd15aca59d Mon Sep 17 00:00:00 2001 From: zeus Date: Mon, 12 Oct 2020 22:40:52 +0300 Subject: [PATCH] cut --- cut/0_Cutting_Content/code | 4 +- cut/0_Cutting_Content/info | 12 ---- cut/1_Advanced_Displays/code | 25 -------- cut/1_Advanced_Displays/codeanswer | 4 -- cut/1_Advanced_Displays/codehelp | 8 --- cut/1_Advanced_Displays/info | 62 ------------------- cut/1_Advanced_Displays/q-info | 8 --- cut/1_Cutting_Column/code | 5 ++ cut/1_Cutting_Column/codeanswer | 1 + cut/1_Cutting_Column/codehelp | 2 + .../data | 0 cut/1_Cutting_Column/info | 26 ++++++++ cut/1_Cutting_Column/q-info | 9 +++ cut/intro | 8 +++ index_cut.yml | 20 +++--- 15 files changed, 63 insertions(+), 131 deletions(-) delete mode 100644 cut/1_Advanced_Displays/code delete mode 100644 cut/1_Advanced_Displays/codeanswer delete mode 100644 cut/1_Advanced_Displays/codehelp delete mode 100644 cut/1_Advanced_Displays/info delete mode 100644 cut/1_Advanced_Displays/q-info create mode 100644 cut/1_Cutting_Column/code create mode 100644 cut/1_Cutting_Column/codeanswer create mode 100644 cut/1_Cutting_Column/codehelp rename cut/{1_Advanced_Displays => 1_Cutting_Column}/data (100%) create mode 100644 cut/1_Cutting_Column/info create mode 100644 cut/1_Cutting_Column/q-info diff --git a/cut/0_Cutting_Content/code b/cut/0_Cutting_Content/code index 436833e..a4167e0 100644 --- a/cut/0_Cutting_Content/code +++ b/cut/0_Cutting_Content/code @@ -1,11 +1,11 @@ echo "Cutting Contents of a file on the standard output (stdout)." -echo "----------------------------------------------------------" +echo "-------------------------------" cut -b1,3 $LLO_DATAFILE | head -5 echo "" echo "Cutting Contents of a file on the standard output (stdout)." -echo "-------------------with ranges---------------------------------------" +echo "-----with ranges-----" cut -b1-5,10-15 $LLO_DATAFILE | head -5 diff --git a/cut/0_Cutting_Content/info b/cut/0_Cutting_Content/info index 103c5e2..19c49ae 100644 --- a/cut/0_Cutting_Content/info +++ b/cut/0_Cutting_Content/info @@ -1,16 +1,4 @@ -Cut parts of a line by *byte position*, *character* and *field*. - -Cut command slices a line and extracts the text. It is necessary to specify option with command otherwise it gives error. - - -[source,bash] ----- -cut OPTION [FILE] -e.g. -cut $LLO_DATAFILE | head -5 ----- - *-b(byte):* To extract the specific bytes, you need to follow -b option with the list of byte numbers separated by comma. [source,bash] diff --git a/cut/1_Advanced_Displays/code b/cut/1_Advanced_Displays/code deleted file mode 100644 index 2074545..0000000 --- a/cut/1_Advanced_Displays/code +++ /dev/null @@ -1,25 +0,0 @@ - -echo 'Display tab characters as ^I' -echo "-------------------------------" - -cat -T $LLO_DATAFILE | head -9 -echo "" - -echo "Display non printing characters" -echo "-------------------------------" - -cat -v $LLO_DATAFILE | head -9 -echo "" - -echo "Suppress repeated empty lines" -echo "-------------------------------" - -cat -s $LLO_DATAFILE | head -9 -echo "" - -echo "In case, you need to use the -v, -E and -T option together, you can just use the -A command line option." -echo "-------------------------------" - -cat -A $LLO_DATAFILE | head -9 -echo "" - diff --git a/cut/1_Advanced_Displays/codeanswer b/cut/1_Advanced_Displays/codeanswer deleted file mode 100644 index 99870b6..0000000 --- a/cut/1_Advanced_Displays/codeanswer +++ /dev/null @@ -1,4 +0,0 @@ -tmpfile=$(mktemp /tmp/test1.XXXXXX) -cat -A $LLO_DATAFILE | head -5 > $tmpfile -cat $tmpfile - diff --git a/cut/1_Advanced_Displays/codehelp b/cut/1_Advanced_Displays/codehelp deleted file mode 100644 index 4879593..0000000 --- a/cut/1_Advanced_Displays/codehelp +++ /dev/null @@ -1,8 +0,0 @@ -Use *mktemp* to create a temporary file in _/tmp_ - -run - -[source,bash] ----- -mktemp --help ----- diff --git a/cut/1_Advanced_Displays/info b/cut/1_Advanced_Displays/info deleted file mode 100644 index 2908719..0000000 --- a/cut/1_Advanced_Displays/info +++ /dev/null @@ -1,62 +0,0 @@ -The cat command also allows - -- Display tab characters as ^I - -[source,bash] ----- -display tab characters as ^I ----- - -For example: - -[source,bash] ----- -cat -T $LLO_DATAFILE | head -9 ----- - - -- Display non printing characters - -For example: - -[source,bash] ----- -cat -v $LLO_DATAFILE | head -9 ----- - -- Suppress repeated empty lines - -For example: - -[source,bash] ----- -cat -s $LLO_DATAFILE | head -9 ----- - -[INFO] -==== -In case, you need to use the -v, -E and -T option together, you can just use the -A command line option. -==== - -For example: - -[source,bash] ----- -cat -A $LLO_DATAFILE | head -9 ----- - -[INFO] -==== - -DATAFILE - -The datafile contains aggregate individual statistics for 67 NBA seasons. from basic box-score attributes such as points, assists, rebounds etc., to more advanced money-ball like features such as Value Over Replacement. - -Take a look in -link:https://git.swarmlab.io:3000/llo/LabLearningObject/src/branch/master/data/nba_statistics_glossary[Glossary^] -for a detailed column description - -ENVIRONMENT VARIABLE: LLO_DATAFILE - -==== - diff --git a/cut/1_Advanced_Displays/q-info b/cut/1_Advanced_Displays/q-info deleted file mode 100644 index e82c11e..0000000 --- a/cut/1_Advanced_Displays/q-info +++ /dev/null @@ -1,8 +0,0 @@ - -Create a temporary file and put output with - -[source,sh] ----- -cat -A $LLO_DATAFILE | head -5 > ... ----- - diff --git a/cut/1_Cutting_Column/code b/cut/1_Cutting_Column/code new file mode 100644 index 0000000..8782442 --- /dev/null +++ b/cut/1_Cutting_Column/code @@ -0,0 +1,5 @@ + +echo "Cutting Contents of a file on the standard output (stdout)." +echo "-----with ranges-----" + +cut -c1-5,10-15 $LLO_DATAFILE | head -5 diff --git a/cut/1_Cutting_Column/codeanswer b/cut/1_Cutting_Column/codeanswer new file mode 100644 index 0000000..4169906 --- /dev/null +++ b/cut/1_Cutting_Column/codeanswer @@ -0,0 +1 @@ +grep "Jordan" $LLO_DATAFILE | cut -c 8- | head -5 diff --git a/cut/1_Cutting_Column/codehelp b/cut/1_Cutting_Column/codehelp new file mode 100644 index 0000000..c509f59 --- /dev/null +++ b/cut/1_Cutting_Column/codehelp @@ -0,0 +1,2 @@ + +-b It uses a special form: selecting bytes upto the end of the line diff --git a/cut/1_Advanced_Displays/data b/cut/1_Cutting_Column/data similarity index 100% rename from cut/1_Advanced_Displays/data rename to cut/1_Cutting_Column/data diff --git a/cut/1_Cutting_Column/info b/cut/1_Cutting_Column/info new file mode 100644 index 0000000..78d8050 --- /dev/null +++ b/cut/1_Cutting_Column/info @@ -0,0 +1,26 @@ + +*-c(column):* To extract the specific character. + +This can be a list of numbers separated comma or a range of numbers separated by hyphen(-) + +[source,bash] +---- +cut -c 1-5 $LLO_DATAFILE | head -5 +---- + + +[INFO] +==== + +DATAFILE + +The datafile contains aggregate individual statistics for 67 NBA seasons. from basic box-score attributes such as points, assists, rebounds etc., to more advanced money-ball like features such as Value Over Replacement. + +Take a look in +link:https://git.swarmlab.io:3000/llo/LabLearningObject/src/branch/master/data/nba_statistics_glossary[Glossary^] +for a detailed column description + +ENVIRONMENT VARIABLE: LLO_DATAFILE + +==== + diff --git a/cut/1_Cutting_Column/q-info b/cut/1_Cutting_Column/q-info new file mode 100644 index 0000000..0b8a085 --- /dev/null +++ b/cut/1_Cutting_Column/q-info @@ -0,0 +1,9 @@ + +Try to run + +[source,sh] +---- +cut -c 3- $LLO_DATAFILE | head -5 +---- + +and see the Results! diff --git a/cut/intro b/cut/intro index b3cd827..251d339 100644 --- a/cut/intro +++ b/cut/intro @@ -2,5 +2,13 @@ It is used for cutting out the sections from each line of files and writing the result to standard output. +Cut command slices a line and extracts the text. + +Cut parts of a line by *byte position*, *character* and *field*. + +[source,bash] +---- +cut OPTION [FILE] +---- In this *LO*, we will see the most used cat Commands examples in Linux. diff --git a/index_cut.yml b/index_cut.yml index 4e3c956..3719dc4 100644 --- a/index_cut.yml +++ b/index_cut.yml @@ -3,7 +3,7 @@ base_url: "https://git.swarmlab.io:3000/llo/LabLearningObject/raw/branch/master" author: "zeus" intro: "intro" - 0_Display_Content: + 0_Cutting_Content: display_name: "Cutting_Content" swarmlabservice: "os2" info: @@ -26,25 +26,25 @@ points: "" # ELO output: log: "bash" - 1_Advanced_Displays: - display_name: "Advanced_Displays" + 1_Cutting_Column: + display_name: "Cutting_Column" swarmlabservice: "os2" info: - file: "1_Advanced_Displays/info" + file: "1_Cutting_Column/info" code: lang: "bash" - exec: "/bin/bash" - file: "1_Advanced_Displays/code" - data: "1_Advanced_Displays/data" + exec: "1_Cutting_Column/bin/bash" + file: "1_Cutting_Column/code" + data: "/data" options: "" mimetype: "bash" output: log: "console" mimetype: "bash" challenge: - question: "1_Advanced_Displays/q-info" - codehelp: "1_Advanced_Displays/codehelp" - codeanswer: "1_Advanced_Displays/codeanswer" + question: "1_Cutting_Column/q-info" + codehelp: "1_Cutting_Column/codehelp" + codeanswer: "1_Cutting_Column/codeanswer" mimetype: "bash" points: "" # ELO output: