PrettyPrintGmail : Chrome extension to clean up printing for Gmail emails via /r/chrome_extensions

PrettyPrintGmail : Chrome extension to clean up printing for Gmail emails

Submitted July 08, 2015 at 11:50PM by anicecreamhappiness
via reddit


Top Secret USAF Europe document about extraterrestrial opinion for origins of flying saucers, 1948 [820 × 1152] via /r/ArchivePorn

Top Secret USAF Europe document about extraterrestrial opinion for origins of flying saucers, 1948 [820 × 1152]

Submitted July 04, 2015 at 07:43AM by marquis_of_chaos
via reddit

YSK what to do in an emergency prior to having the paramedics show up. via /r/YouShouldKnow

YSK what to do in an emergency prior to having the paramedics show up.

Hi everyone, I'm a paramedic and I have had a few instances recently of bystanders that were either doing things that weren't great, or that didn't know what to do for a friend / loved one and asked. Now, I think everyone should take a first aid class or at minimum a CPR class, but not everyone does. For the average person though there are really only three things that we want a person to do before we're on scene:

  • CPR on someone that you think is dead. Don't sweat it if you're wrong, if you aren't a professional it's incredibly difficult in an emergency to really know for sure. Remember that doing or not doing CPR is about whether you think you feel a pulse or not and not whether there really is one. Better to err on the side of doing it if you think they are dead. If you aren't CPR trained the 911 dispatcher can give you instructions as well. It's not rocket science, and our biggest issue in EMS with this is people doing nothing because they think they will do it wrong. Bad CPR is better than no CPR. When we get to a person down that has no CPR started by bystanders, the odds of us saving them decrease drastically. If you read this and aren't comfortable with the thought of doing CPR you really should go take a CPR class. Call your local ambulance service, almost all of them have free public CPR training.

  • Stop major, life threatening bleeding. How does a lay person know if it's life threatening? It might be obvious or it might not. If you aren't sure err on the side of stopping the bleeding. Use one thin piece of cloth or gauze and a lot of pressure. Don't add more gauze, if what you are using becomes saturated that's an indication that the bleeding isn't controlled with pressure and the person need a tourniquet. There is no point in covering it with more material, that just makes it so you don't see them bleeding to death. One of the things I look for is a "stream" of blood. If it's arterial it may well squirt or pulsate with the heartbeat, but ultimately if it's enough bleeding to form a solid stream, that bothers me. What I mean by that is this: If you stood up and cut your arm, causing it to bleed a little, it would likely drip off the end of your arm to the floor, dripping is generally not life threatening. If you cut your arm more seriously the bleeding would be enough to cause a solid stream of blood and "pour" onto the ground. That to indicates what I would refer to as "serious" bleeding. The key here though is pressure on the spot that's bleeding. You aren't trying to "clot" the blood, you're just trying to stick your finger in the hole in the boat. Once you have controlled the bleeding, never let go until a paramedic asks you to. No mater what (unless it becomes unsafe), there is no guarantee that if you lose control of that bleeding anyone will be able to control it again. With streaming and dripping I'm talking about immediate after the injury as well, there could be slowed bleeding and dripping as the patient runs out of blood volume. You would be tipped off to that case be their literally being a pool or trail of blood around the person.

  • Finally I want you to open the airway of unconscious people with a pulse. Use a head tilt chin lift. The vast majority of people who die from something like alcohol poisoning actually just die from becoming unconscious in a way that their away is blocked and can't breathe. This can be prevented with simple manual manipulation of the head.

That's pretty much it. There isn't really a need for bandaging, splinting, etc. as I'm going to remove anything bystanders did in my assessment and re-apply professionally. It can be helpful to calm a person down to cover their injury though. I'm not saying you shouldn't do anything else, I'm just saying anything else is extra.

Never stop on or adjacent to a roadway just call 911. That's the most dangerous place in the country, never find yourself standing on a road. Car broken down? You should be 100ft off the side of the road. But that's a tip for another day.

Finally, this is not medical advice. This is advice for lay people to do without training. Although they vary in specifics and no one can ever promise you that your actions are without liability, you should be covered by Good Samaritan laws in most places following this advice.

Let me know if you have any questions!

Submitted July 03, 2015 at 02:25PM by SDAdam
via reddit

Single line awk commands that are not in awk1line via /r/commandline

Single line awk commands that are not in awk1line

Please expand the list or point out any errors or improvements in the comments. Many of these commands are also included in is a post like this for jq examples, and is a post like this for functions from my .bashrc.

Like comm -13 <(sort file1) <(sort file2) but without sorting. If file1 can be empty, replace NR==FNR with FILENAME==ARGV[1], or with ARGIND==1 in gawk.

awk 'NR==FNR{a[$0];next}!($0 in a)' file1 file2 

Like sort|uniq -c|sort -n|sed 's/^ *//'.

gawk '{++a[$0]}END{PROCINFO["sorted_in"]="@val_num_asc";for(i in a)print a[i],i}' 

Like sort -uk3,3 but without sorting.

awk '!a[$3]++' 

Like gsed '3~7!d' or sed -n '3,${p;n;n;n;n;n;n;}'.

awk NR%7==3 

Like grep '^[^;]*;[^;]*;[^;]*$'.

awk -F\; NF==3 

Sort by count, like sort|uniq -c|sort -nk1,1|sed 's/^ *[^ ]* //'.

gawk '{++a[$0]}END{PROCINFO["sorted_in"]="@val_num_asc";for(i in a)print i}' 

Like (x=$(cat);grep pattern<<<"$x";grep -v pattern<<<"$x").

awk '{if(/pattern/)print;else x=x$0"\n"}END{printf"%s",x}' 

Like tee >(head>/dev/tty)|wc -l.

awk 'NR<=10;END{print NR}' 

Like while IFS= read -r l;do printf %s\\n "$x$l";done. This uses an environment variable instead of -v because awk interprets escape sequences in variables passed with -v.

x="$x" awk '{print ENVIRON["x"]$0}' 

Like sort|uniq -c|awk '$1==5'|sed 's/^ *[^ ]* //' but print the lines in a different order.

awk '{++a[$0]}END{for(i in a)if(a[i]==5)print i}' 

Like grep -Fxf file1 file2;grep -Fxvf file1 file2.

awk 'NR==FNR{a[$0];next}{if($0 in a)print;else x=x$0"\n"}END{printf"%s",x}' file1 file2 

Print lines that contain an odd number of backticks.

awk -F\` NF%2==0 

Like sort|uniq -d but without sorting.

awk '++a[$0]==2' 

Like sort|uniq -u but without sorting.

awk '{a[NR]=$0;++b[$0]}END{for(i in a)if(b[a[i]]==1)print a[i]}' 

Print the lines of file2 whose second field is one of the lines of file1. With a0(){ gawk -e'ARGIND==1{a[$0];next}' -e"$@"; }, you can also use a0 '$2 in a' file1 file2.

awk 'NR==FNR{a[$0];next}$2 in a' file1 file2 

Like tee >(wc -l>/dev/tty)|sort -u|wc -l.

awk '{a[$0]}END{print NR"\n"length(a)}' 

Replace three or more consecutive empty lines with two empty lines.

awk '/^$/{if(++n<=2)print;next}{n=0}1' 

Scale a list of numbers so the smallest number is 0.0 and the largest is 1.0.

awk '{if($0>max)max=$0;if($0<min)min=$0;a[NR]=$0}END{for(i in a)print(a[i]-min)/(max-min)}' 

Print lines in file2 where no part of a comma-delimited list in the fourth column is in file1.

awk 'NR==FNR{a[$0];next}{split($4,b,",");for(i in b)if(b[i]in a)next}1' file1 file2 

Like sed -n '/pattern/{n;n;p;}'. awk '/pattern/{getline;getline;print}' would print the last line when the last or second last line matches the pattern.

awk '/pattern/&&getline&&getline' 

Like sed '/pattern/{n;s/aa/bb/;}'.

awk '/pattern/{print;getline;sub(/aa/,"bb")}1' 

Like sed /pattern/,/^/d.

awk '/pattern/{getline;next}1' 

Like gdate -d@12345 +%T.

echo 12345|awk '{printf"%02d:%02d:%02d\n",$0/3600,$0%3600/60,$0%60}' 

Like gdate -d'1970-01-01 23:59:59' +%s.

echo 23:59:59|awk -F: '{print 3600*$1+60*$2+$3}' 

Like gsed /pattern/Q or sed '/pattern/,$d'.

awk '/pattern/{exit}1' 

Like gdate -d@1234567890 '+%F %T'. gawk and mawk have strftime but nawk doesn't.

awk 'BEGIN{print strftime("%F %T",1234567890)}' 

Like tac file|awk '!a[$0]++'|tac.

awk 'NR==FNR{a[$0]=NR;next}a[$0]==FNR' file{,} 

Delete each line that matches a pattern and two lines after it.

awk '/pattern/{n=3}n{n--;next}1' 

Like gsed 0~4G.

awk '1;NR%4==0{print""}' 

Like grep -A2 pattern but don't print dashes between matches.

awk '/pattern/{for(i=NR;i<=NR+2;i++)a[i]}NR in a' 

Like sed -n s/^prefix//p.

awk 'sub(/^prefix/,"")' 

Like ghead -n-10.

awk 'NR>n{print a[NR%n]}{a[NR%n]=$0}' n=10 

Like tac|gsed '/^---$/Q'|tac.

awk '{if(/^---$/){x=""}else{x=x$0"\n"}}END{printf"%s",x}' 

Like (gsed -u 1q;sort).

awk 'NR==1;NR>1{print|"sort"}' 

Like sed 1,/pattern/s/aa/bb/g.

awk 'NR==1,/pattern/{gsub(/aa/,"bb")}1' 

Like sed 2rfile2 file1.

awk '1;NR==2{system("cat file2")}' file1 

Like lam -f30 <(cut -f3 file.tsv) -s' ' <(cut -f4 file.tsv).

awk -F\\t '{printf"%-30s %s\n",$3,$4}' file.tsv 

Like sed $(($(wc -l<file)/2))q file.

awk 'NR==FNR{n=NR;next}FNR<=n/2' file{,} 

Like gsed '/pattern/!b;s/aa/bb/g;:1;n;b1'.

awk '/pattern/&&!seen{gsub(/aa/,"bb");seen=1}1' 

Like gwc -L.

awk '{if(length>max)max=length}END{print max}' 

Like sed -n '/pattern/{=;q;}'.

awk '/pattern/{print NR;exit}' 

Like sort -n|tail -n1. NR==1|| is needed when the input contains only nonpositive numbers.

awk 'NR==1||$0>max{max=$0}END{print max}' 

Like grep -E '^[^;]*;[0-9]+(;|$)'.

awk -F\; '$2~/^[0-9]+$/' 

Print all pairs of lines in file1 and file2 separated by a space.

awk 'NR==FNR{a[NR]=$0;next}{for(i in a)print$0,a[i]}' file2 file1 

Like paste -d' ' file1 file2, assuming that the files have the same number of lines.

awk 'NR==FNR{a[NR]=$0;next}{print$0,a[FNR]}' file2 file1 

Like while read -r x y z;do printf %s\\n "$y">>"$x.txt";done. The parentheses are required in nawk but not in gawk or mawk.

awk '{print$2>>($1".txt")}' 

Like gsed '/pattern/atext to insert' or sed $'/pattern/a\\\ntext to insert\n'.

awk '1;/pattern/{print"text to insert"}' 

Like grep -l pattern *.

awk '/pattern/{print FILENAME;nextfile}' * 

Like sed -n '1p;$p'.

awk 'NR==1;END{print}' 

Like gsed -u 5q;tail -n5, assuming that the input is 10 lines long or longer.

awk '{a[NR]=$0}END{for(i=1;i<=5;i++)print a[i];for(i=NR-4;i<=NR;i++)print a[i]}' 

Like while IFS= read -r l;do case $l in *"$string")printf %s\\n "$l";;esac;done.

x="$string" awk 'BEGIN{x=ENVIRON["x"];n=length(x)}length>=n&&substr($0,length-n+1,n)==x' 

Like sed /pattern/G.

awk '1;/pattern/{print""}' 

Print the number nearest to 50 on a list of numbers.

awk '{d=$0-50;if(d<0)d=-d;if(NR==1||d<min){min=d;minvalue=$0}}END{print minvalue}' 

Print lines whose line number is in line-numbers-to-print.txt.

awk 'NR==FNR{a[$0];next}FNR in a' line-numbers-to-print.txt - 

Like sed '/aa/{/bb/!d;}'.

awk '!/aa/||/bb/' 

Transpose a matrix, like rs -c' ' -C' ' -T.

awk '{for(i=1;i<=NF;i++){a[NR,i]=$i}}NF>w{w=NF}END{for(j=1;j<=w;j++){x=a[1,j];for(i=2;i<=NR;i++){x=x" "a[i,j]}print x}}' 

Print the number of commas on each line.

awk -F, '{print NF-1}' 

Like for f in *;do wc -l<"$f";done|sed 's/^ *//'. nawk and mawk don't have ENDFILE.

gawk 'ENDFILE{print FNR}' * 

Like wc -l *|sed '1!{$d;}'|sed 's,^ *,,'.

gawk 'ENDFILE{print FNR,FILENAME}' * 

Like sed -n '1{p;n;};/pattern/p'.

awk 'NR==1||/pattern/' 

Like sed -e'/aa.*bb/b' -e/aa/d.

awk '/aa/&&!/aa.*bb/{next}1' 

Like sed "s/pattern/$(sed 's/[&/\\]/\\&/g'<<<"$x")/g".

x=${x//\\/\\\\};x="${x//&/\\&}" awk '{gsub(/pattern/,ENVIRON["x"])}1' 

Like cat -s, but don't print an empty line at the start of the input if the input starts with one or more empty lines. This and cat -s both print an empty line at the end of the input if the input ends with one or more empty lines.

awk '{if(/./||prev!="")print;prev=$0}' 

Print the first line of each paragraph.

awk -v RS= -F\\n '{print$1}' 

Sort lines within each paragraph. Without the close function this would sort the whole input together.

awk -v RS= '{print|"sort";close("sort");print""}'|sed \$d 

Sort lines by the number of times the second field occurs in the input.

gawk '{++a[$2];b[$2]=b[$2]$0"\n"}END{PROCINFO["sorted_in"]="@val_num_asc";for(i in a)printf"%s",b[i]}' 

Like sed 'p;s/aa/bb/g'|paste -d' ' - -.

awk '{x=$0;gsub("aa","bb");print x,$0}' 

Like sort|uniq -c|awk '$1<50'|sed 's/^ *[^ ]* //' but print the lines in a different order.

awk '{++a[$0]}END{for(i in a)if(a[i]<50)print i}' 

Like grep -Ff file1 file2.

awk 'NR==FNR{a[$0];next}{for(i in a)if(index($0,i))print}' file1 file2 

Like grep -Eo '[0-9]+'|jq -s add. nawk and mawk don't have RT and nawk doesn't treat a two character or longer RS as a regex.

gawk '{x+=RT}END{print x}' 'RS=[0-9]+' 

Replace linefeeds with spaces inside paragraphs.

gawk -vRS= '{gsub("\n"," ");printf"%s",$0 RT}' 

Subtract the smallest number from all numbers on a list of numbers.

awk '{a[NR]=$0;if(NR==1||$0<min)min=$0}END{for(i in a)print a[i]-min}' 

Like sed '/start/,${/pattern/d;}'.

awk '/start/,0{if(/pattern/)next}1' 

Like grep -H pattern *.txt|cut -d: -f1|uniq -c|sed 's/^ *//'.

gawk '/pattern/{++n}ENDFILE{print n,FILENAME;n=0}' *.txt 

Print the RMS of a list of numbers.

awk '{x+=$0*$0}END{print sqrt(x/NR)}' 

Print lines that start with one of the specified tags before other lines grouped by the tags.

awk '{if(/^(tag1|tag2|tag3) /)print|c;else x=x$0"\n"}END{close(c);printf"%s",x}' c='sort -sk1,1' 

Print the number of unique lines only in the first file, only in the second file, and in both files, followed by the total number of lines only in the first file and only in the second file, followed by the total number of lines in the first file and in the second file.

awk 'FILENAME==ARGV[1]{a[$0];next}{b[$0];if($0 in a&&$0 in b)c[$0]}END{la=length(a);lb=length(b);lc=length(c);print la-lc,lb-lc,lc"\n"la,lb"\n"NR-FNR,FNR}' file1 file2 

Like while IFS= read -r l;do printf %s\\n "${x//aa/$l}";done.

x="$x" awk '{gsub("\\","\\\\");gsub("&","\\\\&");x=$0;$0=ENVIRON["x"];gsub("aa",x)}1' 

Print the median of a list of numbers.

sort -n|awk '{a[NR]=$0}END{if(NR%2==1)print a[int(NR/2)+1];else print(a[NR/2-1]+a[NR/2])/2}' 

Print lines in filenames2 whose basename is the basename of one of the lines of filenames1.

awk -F/ 'NR==FNR{a[$NF];next}$NF in a' filenames1 filenames2 

Remove nonempty duplicate lines.

awk '/^$/||!a[$0]++' 

Print the geometric mean of a list of numbers.

awk '{x*=$0}END{print x^(1/NR)}' x=1 

Print the last five lines of each paragraph, assuming that each paragraph contains five or more lines.

awk -v RS= -F\\n '{for(i=NF-4;i<=NF;i++)print$i}' 

Print lines whose length is 81 characters or more after other lines.

awk '{if(length<=80)print;else x=x$0"\n"}END{printf"%s",x}' 

Remove lines that appeared before within the previous ten lines.

awk '!($0 in a)||a[$0]<NR-11;{a[$0]=NR}' 

Print lines whose first field is the first field of some previous line but whose second field is not the second field of the same previous line.

awk '$1 in a&&!($2 in a[$1]);{a[$1][$2]}' 

Print lines whose second field is the second field of one of the five previous lines.

awk '{for(i=NR-1;i>=NR-5;i--){if($2==a[i]){print;next}}a[NR]=$2}' 

Indent the first line of each paragraph.

awk '{if((NR==1||!x)&&/./)$0=" "$0;x=/./}1' 

Indent all lines except the first line of each paragraph.

awk '{if(x&&/./)$0=" "$0;x=/./}1' 

Print paragraphs that contain a pattern once.

awk 'gsub(/pattern/,"&")==1' RS= 

Print the line numbers of the lines of file2 that are also in file1.

awk 'NR==FNR{a[$0];next}$0 in a{print FNR}' file1 file2 

Remove consecutive duplicate lines that match a pattern.

awk '!($0==prev&&/pattern/);{prev=$0}' 

Sort lines in file2 by the line number of the second field in file1.

awk 'NR==FNR{a[$0]=NR;next}{print a[$2],$0}' file1 file2|sort -n|cut -d\ -f2- 

Test if a list of numbers is strictly increasing.

awk '$0<=prev{exit 1}{prev=$0}';echo $? 

Delete lines in file2 up to the last line that is also in file1. You can also use tac file2|awk 'NR==FNR{a[$0];next}$0 in a{exit}1' file1 -|tac.

gawk 'ARGIND==1{a[$0]}ARGIND==2&&$0 in a{b=FNR}ARGIND==3&&FNR>b' file1 file2{,} 

Remove the last field. This works with gawk and mawk but not with nawk.

awk NF-- 

Convert CRLF or CR to LF.

gawk 1 RS='\r\n?|\n' 

Like xxd -p|tr -d \\n, even though this does not work with multibyte characters.

LC_ALL=C gawk -vRS='.{1}' -iord '{printf"%02x",ord(RT)}' 

Replace two or more consecutive linefeeds with a single linefeed and replace single linefeeds with a tab. This also removes empty lines from the start and end of the input.

awk '{$1=$1}1' RS= FS=\\n ORS=\\n OFS=\\t 

Swap every pair of two lines assuming that the total number of lines is even, like sed -n 'h;n;p;g;p'.

awk '{getline x;print x}1' 

Insert a space to the start of lines in file2 that are also in file1.

awk 'NR==FNR{a[$0];next}$0 in a{printf" "}1' file1 file2 

Like grep -n pattern|cut -d: -f1|tail -n1.

awk '/pattern/{x=NR}END{print x}' 

Round the fractional parts of numbers with a fractional part to two digits.

awk '{while(match($0,/[0-9]+\.[0-9]+/)){printf"%s%.2f",substr($0,1,RSTART-1),substr($0,RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH)};print}' 

Print a random integer between 1 and 6. This prints the same number twice when it is ran twice within the same second.

awk 'BEGIN{srand();print int(6*rand())+1}' 

Like shuf -rn4.

awk '{a[NR]=$0}END{srand();for(i=1;i<=4;i++){print a[int(rand()*NR)+1]}}' 

Like for f in *.txt;do echo "$f";cat "$f";done.

awk 'FNR==1{print FILENAME}1' *.txt 

Like fold -w70.

awk '{while(length>w){print substr($0,1,w);$0=substr($0,w+1)}}1' w=70 

Print the standard deviation of a list of numbers.

awk '{x+=$0;y+=$0^2}END{print sqrt(y/NR-(x/NR)^2)}' 

Submitted January 23, 2016 at 11:15AM by 18252
via reddit