awk:

awk is the widely used utility for text manipulation in text based files. It can do a lot of complicated pattern matching, stripping, etc that will require bunch of code in any other scripting language. awk and sed are very commonly used together and almost suffice for 99.9% of text manipulation encountered in real life.

awk is a full scripting languages, though it's most suited for text manipulation. awk was named after the initials of the people who wrote it. Now we have the GNU implementation of awk called gawk. gawk is the one that is installed on all Linux systems, and awk actually is a soft link to gawk.

$ awk --version => shows "GNU Awk 4.0.2"

Good tutorial on awk: https://www.howtogeek.com/562941/how-to-use-the-awk-command-on-linux/

Syntax:

awk syntax is extremely simple. The entire awk program is enclosed in single quotes ('). It has rules, comprised of patterns and actions.

  • Patterns: Patterns are enclosed in curly braces { }. If no pattern is provided, then it works on every line of text since all lines match.
  • Action: Action is executed on text that matches the patterns.
  • Rule: Together, a pattern and an action form a rule. 
  • Fields: Fields are separate regions within a line. We define fields since that's the only way we can extract certain data within a piece of text. By default, awk considers a field to be a string of characters surrounded by whitespace, the start of a line, or the end of a line. Fields are identified by a dollar sign ($) and a number. So, $1 represents the first field, $2 the 2nd field, and $NF the last field (NF stands for number of fields). $0 represents the full line from start to end. If we want to change the input field separator to something else, we should use option -F (separator string) option to tell awk to use that (i.e -F: uses colon (:) as the separator to figure out fields for input file). NOTE: no space b/w -F and : Also, this -F option is before we we write the pgm in quotes. ex: awk -F: '{print $2}'. We can also write awk 'FS=":" {print $2}' => This also does the same thing as FS means i/p field separator.
  • awk works on an input text file and can show output on screen using "print" function, or redirect the output to another file. Just as input file has fields, o/p file also has field separator which is a space by default. To change the separator to something else, we use option OFS=":" (output field separator is a :). This option is to be used within quotes (i.e as part of the awk pgm). ex: awk 'OFS=":" {print $1}'. This OFS applies to only those print statements that are following that OFS.

Few more awk cmd:

  • print: print function prints strings by enclosing in double quotes, i.e print "my name is". To print var, we don't need quotes. ex: {print "my name is"} {print $name}. or in one as {print "my name is", $name}. If $name is put within quotes, then it's treated as a literal, and is printed as is =>"my name is $name". comma is optional, however we put as it automatically invokes a space. See below ex:
    • print specific field of certain cmd:
      • ls -al | awk '{print "3rd field" $3}' => This takes the o/p of ls -al cmd and prints "3rd field" followed by the third field of each line, which is the userid of the owner. With no comma, there is no space b/w field and $3. To invoke space either add a space within the text as "3rd field " or add a comma.
      • awk '{print $1 $4}' input.txt => This prints field 1 and field 4 of each line in file input.txt. However, the printed fields will have no space b/w them, so they will appear as one word. The output field separator is invoked on putting a comma, i.e {print $1,$4}. To change it to something else, use OFS=":". i.e awk 'OFS=":" {print $1 $4}' input.txt
    • convert field to number: When we get certain field from a file, let's say $3, it's still grepped a sa string. So, if we try to use that number outside of awk, it will error, complaining it's not numeric. In such cases, add 0 to the field to automatically convert it to number.
      • set num1 = `zgrep "Number" *.report.rpt.gz  | awk -F" " '{print $5+0}'; set sum = `echo "$num1 + $num2" | bc -l` => In this, if we just use "print $5" without adding a 0, then that field is returned as a string. Adding it with num2 gives an error. But if we add 0, then num1 automatically is cast to integer/float and and then summing works.
  • BEGIN/END rules: A BEGIN rule is executed once before any text processing starts. In fact, it’s executed before awk even reads any text. An END rule is executed after all processing has completed. You can have multiple BEGIN and END rules, and they’ll execute in order. We can have as many lines of cmd as we want in BEGIN and END by enclosing them in {}, and they will execute only once in begin and end of awk program.
  • awk as script: We can also write a full script in awk, especially when pgm gets big. # are comments. First line needs to be #!/usr/bin/awk -f. See the ex on link above.

Few examples of awk:

  • pattern matching and conditions: We an add specific conditions:
    • awk -F: 'BEGIN {print "START"; FS="/"; OFS=":"} $3 >= 1000 {print $1,$6} END {print "DONE"}' /etc/passwd => This prints 1st and 6th entries only if 3rd entry is >= 1000.
    • awk '/^UUID/ {print $1}' /etc/fstab => This searches for pattern UUID at start of line, and all lines that have that, have their first field printed.
    • To extract all lines between given markers => This is very common use case, where we want to use scripts to grep for text b/w markers:
      • awk '/## START OF MARKER ##/{a=1}/## END OF MARKER ##/{print;a=0}' /home/my.rpt > ~/extracted_marker.txt => extracted_marker.txt has all text b/w "START" and "END". "a" is just a var (can be any var name). CMD "print" is optional, as by default print happens.
      • awk '/## START OF MARKER ##/{flag=1} flag; /## END OF MARKER ##/{flag=0}' /home/my.rpt > ~/extracted_marker.txt => alternative way of above cmd. The line "flag" prints lines while flag is set. This is a shortcut of this cmd => {if (flag==1) print}

 

Substitute text between specific Markers with contents from another file: This is not easy. We saw how to do this in sed. But that sed cmd doesn't work in any other shell besides bash. So, we have an alternative way in awk cmd, that achieves this functionality.

awk 'BEGIN {flag=0;} /START of pattern/,/END of pattern/ { if (flag == 0) { system("cat replacement.txt"); flag=1} next } 1' original_file.txt > modified_file.txt => Here we grep for markers in original_file.txt and replace all the text b/w those markers (including the markers themselves) with text in replacement.txt. We save the resulting modified file as modified_file.txt (instead of saving as original_file.txt)

However, if are patterns are stored in var, or the file names are var, then we have to get those var outside of single quotes (As anything inside single quote is for awk to evaluate). When we put in double quote, then shell expands it, and then awk just concatenates that when running the cmd.

ex: awk 'BEGIN {flag=0;} /## START OF '"$pat1"' ##/,/## END OF '"$pat2"' ##/ { if (flag == 0) { system("cat /home/'"$name"'_replacement.txt"); flag=1} next } 1' original_file.txt > modified_file.txt

 


 

 

 

 

College Admissions:

Things that you should get into to get into a good college:

The first thing that any college admissions officer wants to see when looking at extracurriculars is that a student sticks with the activities they choose. Devoting oneself to one club and one sports team is far more impressive than trying a new club and a new sports team every year. This shows that a student is able to stick to something and wants to perfect skills and lessons.

The next things that a college admissions officer looks for are passion. In any application, a student should make sure that they explain what they love about the extracurricular activities they chose during their high school years.

The final thing that every college admissions officer looks for is leadership. This is key. Above all, a student should look to assume a leadership role at some point in the extracurriculars they pursue. Through time, leadership roles should be highly possible and will look fantastic on any college application.

Non SDC - extracting lib data

Many times, we want to extract info for std cells from the library (.lib liberty files), such as power consumption, delay for certain FanOut, etc. It's not always feasible to get this from design data, as design may not have the cell we are looking for, or the Fanout of the cell may be different than the Fanout we are interested in. In such cases, we have to instantiate our own dummy design in the current design, and then run SDC or Non SDC cmds to get the required info.

We should use Synthesis tools to get info from library, as it's easy to instantiate our dummy design into the current design. Timing tools, such as PT are not really meant to modify an existing netlist, so they are restricted in how much they allow you to modify the netlist. Most of the times, it's easy to directly modify the netlist and insert your dummy logic in there, but over here, we'll modify the netlist using ECO cmds (For ECO cmds, see in ECO - Engineering Change Order section)

Sample Dummy circuit

Ex: Let's say we want to test the delay for a Fanout of 4 for an inverter in a given library. We should first create such an inverter cell, connect it to port on input and output, and then use a driver on i/p and load on o/p. Below are the steps for extracting lib data using various tools.

PrimeTime:

Create a dummy logic of an inverter where we first instantiate a dummy cell, then connect it to ports and then drive it appr and get timing.

  • Instantiate an inverter:
    • get_lib_cell *tsmc_n3*/INV_NOM_D1_*_SVT => shows INV_D1_NOM_SVT cell.
    • create_cell dummy_test [get_lib_cell *tsmc_n3*/INV_NOM_D1_NOM_SVT] => create an inverter with that std cell
    • get_pins -of [get_cells dummy_test] => This should show pins of Inverter (i.e IN and OUT)
    • get_att [get_pins dummy_test/IN] pin_capacitance_max => should show various attr present in .lib
  • Now create and connect nets on i/p and o/p pins, and then connect to new/existing ports.
    • create_net dummy_in; create_net dummy_out
    • connect_net [get_net dummy_in] [get_pin dummy_test/IN]; connect_net [get_net dummy_out] [get_pin dummy_test/OUT]
    • create_port -direction "out" {dummy_outp}; create_port -direction "in" {dummy_inp} => creation of new ports is not allowed in PT, so we need to use existing ports.
    • connect_net [get_net dummy_in] [get_port EXISTING_SPARE_PORT1] =>This won't work either as port already has a net with the port name, so it violates rule #2 of connect_net
    • disconnect_net -all [get_nets dummy_in]
    • connect_net [get_net -of [get_port EXISTING_SPARE_PORT1] [get_pin dummy_test/IN] => This connects pin to port
  • Now connect load on o/p pin and driver on i/p pin:
    • set load_fo4 [expr [get_att [get_pins dummy_test/I] pin_capacitance_max] * 4] => sets o/p load to 4X i/p load (so that gives FO=4)
    • set_load $load_fo4 [get_pins dummy_test/OUT] => Doesn't work as set_load cmd can only be used on ports and nets, and not on the pins directly.
    • set_load $load_fo4 [get_net dummy_out] => works as it's applied on net.
    • set_input_transition 100 [get_port EXISTING_SPARE_PORT1]  => instead of driving it with a driver cell, we instead directly control the transisition time
    • report_timing -thr dummy_test/OUT -tran -cap => reports delay of cell
    • get_attribute [get_timing_path -thr dummy_test/OUT ] arrival => This also reports delay, but now it can be automated in a script

DC:

 

Disease and Medicines:

Biology is not only about how human body works, but also about what makes it not work, and how to fix it.

Bioavailability of Medicine:

It's the fraction (%) of an administered drug that reaches the blood for systemic circulation. By definition, when a medication is administered intravenously (via veins), its bioavailability is 100%. However, when a medication is administered via routes other than intravenous, its bioavailability is generally lower than that of intravenous due to intestinal endothelium absorption and first pass metabolism. Since the concentration of drug in blood varies with time, the whole area under curve is taken for calculation purpose. Bioavailability refers to avg value as the absorption rate varies greatly among individuals. Bioavailabilty is a very important term for drugs, as your eventual "mg" dosage per day will depend on it's bioavailability.

Link: https://en.wikipedia.org/wiki/Bioavailability

 

Diuresis:

It's the excretion of urine, especially when excessive. In healthy people, excess water drunk is passed in form of extra urine to maintain fluid balance. People with heart failure (HF) and kidney disease have difficulty getting the excess water out of their body, which results in fluid accumulation in body, a condition known as edema.

Diuretics are medicines that help get this extra fluid out of the body, by increasing urine production. As such they benefit people with edema, and are also known as water pills. Diuretics are also used to lower blood pressure (BP) for people with high BP (Hypertension). In such cases, deuretics do lower water in the blood, but the reduction in BP occurs due to other mechanisms. Any removal or absorption of fluid in blood disturbs the balance of electrolytes, such as sodium, potassium, calcium, magnesium, etc in blood. So, people taking deuretics should watch out for these too.

There are mainly three types of diuretic medications.

  • Thiazide: Thiazides are the most commonly prescribed diuretics. They’re most often used to treat high blood pressure. These drugs not only decrease fluids, they also cause your blood vessels to relax. Thiazides are mostly taken with other medications used to lower blood pressure. Examples of thiazides include:
    • chlorthalidone
    • hydrochlorothiazide (Microzide)
    • metolazone
  • Loop diuretics: Loop deuretics are often used to treat heart failure. While Thiazide diuretics are more effective in patients with normal kidney function, loop diuretics are more effective in patients with impaired kidney function. Loop diuretics are also used to treat high BP, though primary use is to for HF patients. Loop diuretics usually have a "ceiling" effect where there is a maximum level of dosage where further increase in dosage will not increase the clinical effect of the drug. Examples of these drugs include:
    • furosemide (Lasix) =>
    • torsemide (Demadex) =>
    • bumetanide => A dose of 40 mg of furosemide is equivalent to 20 mg of torsemide and 1 mg bumetanide.
  • Potassium-sparing diuretics: Above 2 diuretics disturb electrolyte balance and may cause lower potassium in blood (especially for people with low potassium in blood), which is an important nutrient. Potassium sparring diuretics are an answer to that. They reduce fluid levels in your body without causing you to lose potassium.  

 

 


 

Diabetes:

If you have diabetes (which is high levels of sugar or glucose in your blood), you will require to measure your sugar levels multiple times a day, and adjust your dosage of insulin based on that. There are glucose meters that measure the glucose level. These meters themselves are usually free or cheap, but the strips that come wit these are pretty expensive ($1 per strip). Many meters come with 10 free strips and 10 free needles.

Prodigy sells strips for 10 cents per strip for their glucose meter. This is the cheapest option:

Prodigy strips on ebay (13 cents/strip as of Jan, 2025) => https://www.ebay.com/itm/335545752368

 


 

 

Water and Food:

Water and Food are consumed by us, and are needed to keep the body alive. Water provides hydration to cells, while food provides important nutrients needed by the body's cells, which eventually provide energy to body.

Water and food (all food have some water content) are taken in by mouth. We smash and grind it up in the mouth. From the mouth, there's a pipe called esophagus which takes it to the stomach. The stomach mixes it all up with chemicals that start to dissolve it. Bile is added a little later to dissolve fats. The bile also gives the food mass its color brown.

Small/Large Intestine:

This mass of mixed solids and liquids moves through the intestines. Everything that can be broken down is broken down into individual molecules. The whole mass is now considered a liquid with larger solids suspended in it. Even though we drink 2-3 litres of water a day, saliva, gastric juice, bile, etc secreted to the this whole mass makes up like 9 litres of liquid. The individual molecules (good and bad) then are absorbed from the intestines into your bloodstream by actually “soaking” through the intestine wall and through the blood vessel walls waiting on the other side. Some of these molecules are chemically pushed or pulled across into the blood vessels. What is left in the intestines gets drier and drier as more and more water is pulled out and absorbed into the bloodstream.

Food needs to be broken up into smaller molecules. Water, on the other hand, is a very simple molecule, so our body doesn’t have to break it down into smaller, simpler molecules. As a matter of fact, water molecules are so small that they have no problem diffusing through the phospholipid bilayer that forms the cell membrane of human tissues. This cell membrane (presumably) consists of small channels or pores through which water or water-soluble substances can enter, meaning that water is directly absorbed through the epithelial cells that cover humans’ intestinal tract. Small intestine tract has villi which are finger like projections, which are made of epithelial cells. These epithelial cells have brush like border called microvilli, which further increase the surface area for absorption. In short, this means that the small intestine is responsible for the absorption of most of the water that we consume. 90% of the fluid is absorbed in small intestine, and only 10% in large intestine. Blood capillaries are inside the villi, so anything absorbed via these epithelial cells  is passed on to the blood, which carries to all the places in human body.

The kidneys are constantly monitoring the amount of water and other by products and waste products in the bloodstream, such as uric acid, and pull or push them into the urinary tract, to keep the concentration in the blood just right. This all collects in the bladder. It is a mixture of mostly excess, unneeded water and other chemicals such as ammonia. When the bladder is full, we urinate (called urine because of the uric acid).

Meanwhile, the soon-to-be stool keeps moving along and at different parts of the intestine, different molecules are absorbed. It is held in the end of the large intestine. When it is full, we defecate.

Water's Journey thru body: