`
If you find these tutorials useful, Please consider making a donation.

TheFrugalComputerLinuxLogo.png
TheFrugalComputerGuy.png
Linux Command Line 13
Extract and Update Text







Linux Command Line (39) tr

tr is short for translate and translate will change any single character to another single character of your choosing.

tr does not update the file content, tr just reads the file, makes the update and sends the output to the screen

This video shows how to use tr to translate all the letter "a"s in a file to "at symbols"

Multiple letters can be translated in a single command, but each character is translated independently

tr can also be used to delete a characters or character classes or delete the complement of a character (or character class)





 






Linux Command Line (40) sed pt1

sed is short for Stream EDitor and the substitute command for sed it one of the most common features of sed.

sed does not update the file content, sed just reads the file, makes the update and sends the output to the screen

sed works more like a traditional find and replace that most of use are already familiar with

The sed current value search field is a regular expression.

sed commands can be placed in a file and run from that file





 






Linux Command Line (41) sed pt2

continuing on from where we left off in the last video...

sed has two special values for the replacement string the first one is the ampersand. When the ampersand is placed in the replacement string, it will show the RegEx result from the search string.

The second special value is an escaped number, In the RegEx search string, the seach string can be separated into sections with parentheses. Escaped numbers in the replacement string will repalce that escaped number with the RegEx in that number parentheses (escaped number one well be replaced with what is in the first set of parethesis, the escaped number 2 will be replaced with what is in the second set of parenthese, and son on.

sed can also be used to extract or print out only specific lines (like lines five through nine, or lines two through the end of file, or only lines that were udated with the substitute command)





 






Linux Command Line (42) cut

The cut command allows us a quick and easy way to cut data from a file one of three ways. The three ways of cutting text are by bytes, characters, or fields. We are only looking at text files in this tutorial so we will only be cutting characters and fields.

When cutting text by characters, we need to know the starting and ending columns of what we want to cut.

When cutting by fields, it is best to have a file with fields separated by a specific delimiter (like tabs or commas). Tabs is the default input delimiter.

We can specify an output delimiter for the cut fields output.





 






Linux Command Line (43) awk pt1

awk is a programming language, not as complete as Perl or C, but it is a programming language.

A typical awk script will start with awk then have a condition, code, then an input file filename.

awk has some built in variables like NF for Number of Fields and NR for number of Records. These variables can be used as a condition for what rows to update or select.

awk can be used to do the same things as grep

By default, awk identifies fields separated by white-space. An input file delimiter can giving to separate fields by something other than white-space. To set fields by specific columns those columns will need to be defined int he variable FIELDWIDTHS.





 






Linux Command Line (44) awk pt2

awk scripts are run from files in this video. We start with an example used in the previous video run as a line command script and then we look more involved awk scripts run as files.

The awk scripts in this video include examples with with the length function, if-else, as well as the printf.

We also look at the BEGIN and END features of awk and use for-loops with an array and some basic math calculations.

The last example runs an awk script as an executable script with user created functions, while loops, and a calculation.