solution for combining two text files missing different headers - windows

I am running in a windows environment and have not used grep/awk/sed/shell; however, I would like to know what would be the simplest solution for the following issue:
I have two files (they both have headers):
Genetics File. The columns are Animal, Car, Color
Specimen File. The columns are Animal, Color
I would like to combine the two file into one file with all headers present; however, for the specimen file portion to have blank values for Car. The end product would be:
+----------+------+-------+---------------------------------------------------------------------+
| Animal | Car | Color | |
+----------+------+-------+---------------------------------------------------------------------+
| Elephant | Jeep | Grey | (from genetics file [don’t include this text in the resulting file) |
| Dog | Ford | Red | (from genetics file) |
| Cat | | Blue | (from specimen file) |
| Donkey | | Green | (from specimen file) |
+----------+------+-------+---------------------------------------------------------------------+
What would be the simplest solution in a windows environment?
edit: to clarify the reason for those tags is because i believe that those tools are the best suited for this job! I do not want to create a whole c# application just to do this.

The tools referred to in the question, sed, awk, grep, etc., are not native to Windows.
In order to use those them, you will have to make a choice:
Install a unix or linux on your computer, either native, or through virtualisation.
or:
Install a toolkit like Cygwin or UWIN
There's a lot of documentation out there for these projects, but there's a lot to learn, if you're new.
An easy way to get started with virtualisation is to get Oracle's Virtualbox, and a copy of ubuntu linux.

Is this what you want ?
$cat input.ani
|Elephant|Jeep|Grey|
$ cat input.Specimen
| Cat | Blue |
| Dog | White |
| Elephant | Red |
$ cat input.Specimen | awk '{print $1 $2 $3 " " $3 $4 $5 $6 }' >> input.ani
$ cat input.ani
|Elephant|Jeep|Grey|
|Cat| |Blue|
|Dog| |White|
|Elephant| |Red|

On second thought, for a simple solution, I would not recommend against the unix toolset, unless you really want to get learn the environment.
For a Windows system, you could just as well install a good scripting language like python, perl, or ruby.
None of those is trivial, but they have good support, and they have decent installers for windows.
Yet another alternative would be PowerShell, which again, is based on the .Net runtime.

Related

I want to retrieve battery related information(Model information,health information,charge information) through terminal in mac os

I have tried the following command in macOS to get all the battery information:
pmset -g batt
The above command is displaying only one information(i.e 35% discharging).
system_profiler SPPowerDataType | grep "Device Name" | awk '{print $3}'
The above command is displaying device name.
Is there any command by using which together all battery information(Serial Number, Manufacturer, device name, cycle count, charging, etc.),we can fetch. Please help me in finding this. Thanks for your help in advance.
The best command that I could think of is
ioreg -w0 -1 | grep Capacity
For me this returns something like this:
| | "AppleRawCurrentCapacity" = 6417
| | "AppleRawMaxCapacity" = 6834
| | "MaxCapacity" = 6834
| | "CurrentCapacity" = 6417
| | "LegacyBatteryInfo" = {"Amperage"=18446744073709550119,"Flags"=4,"Capacity"=6834,"Current"=6417,"Voltage"=8204,"Cycle Count"=198}
| | "DesignCapacity" = 7150
| | "BatteryData" = {"StateOfCharge"=24064,"Voltage"=8204,"QmaxCell1"=46108,"ResScale"=0,"QmaxCell2"=0,"QmaxCell0"=54044,"CycleCount"=198,"DesignCapacity"=7150}
Don't forget that you can combine multiple commands into one to run after the other has completed with && eg:
system_profiler SPPowerDataType | grep "Device Name" | awk '{print $3}' && ioreg -w0 -1 | grep Capacity
You can also replace the word Capacity with things like board-id
If you want to process all this data I would create a bash script to do it for you,
Because you can cut up the lines to display the info that you want like:
ioreg -l | grep board-id | cut -d \" -f 4
Obviously you can just type this into the terminal but doing this for every command gets a bit tyresome!
Combine many of these commands to make a script (or even in python!) that would process all the data and return it in anyway you would like, if that is possible for what you want to use that data for!
I should think that all the possible accessible battery information is found in system information > power:
Battery Information:
Model Information:
Manufacturer: DP
Device Name: bq20z451
Pack Lot Code: 0
PCB Lot Code: 0
Firmware Version: 511
Hardware Revision: 000a
Cell Revision: 1210
ETC.....
EDIT:
Istats is a free CLI which allows you to view a lot of info but is obviously not native see https://robservatory.com/see-sensor-stats-in-terminal/
To find the battery temp with a single native command! :
bc <<< "scale=3; `ioreg -r -n AppleSmartBattery | grep Temperature | cut -c23-`/100"
Hope this helps

Rendering this pandoc table

+---------------+---------------+--------------------+
| Right | Left | Centered |
+==============:+:==============+:==================:+
| Bananas | $1.34 | built-in wrapper |
+---------------+---------------+--------------------+
I used the standard command
pandoc test.txt -o test.pdf
But I get the above unrendered text. Am I doing something wrong here?
I am new to pandoc tables. Are grid tables fundamentally different than other tables supported by pandoc markdown?
I managed to render this adapted version in stackedit.io
| Right | Left | Centered |
|-:|:-|:-:|
| Bananas | $1.34 | built-in wrapper |
And your version in pandoc/try, which did work as expected. Try specifying the input and output format, and also try a different output format to see if that works.

Taking notes: print two pages per sheet, one blank

I need an automation for PDFs that is a variant of multiple pages per sheet. In this case, I don't need a simple two-pages-per-sheet solution, that's easy. I need to take hand-written notes side by side to the pages. So, here it goes:
Given a PDF, I'd like to print it with two pages per sheet, however, one page must be blank, like this:
+-------+-------+
| P.1 | white |
| | |
| | |
+-------+-------+
+-------+-------+
| P.2 | white |
| | |
| | |
+-------+-------+
etc.
Has anyone an idea to write a script that can automate this?
PS. I know how to do this in LaTeX, but I'd like to avoid the big gun...
If avoiding LaTeX does not mean avoiding usage of any tools that depend on it, then PDFJam (Debian package is texlive-extra-utils) could be of help, see q/a: Gluing (Imposition) PDF documents.
Otherwise you are probably better off with a little script that converts .pdf file pages to images and then merges them with a blank image, ImageMagick is able to do those things.
With Ubuntu:
# install packages
sudo apt-get install enscript ghostscript pdfjam pdftk
source="source.pdf"
output="output.pdf"
# create ps with one blank page
echo -n | enscript -p blank.ps
# convert p2 to pdf
ps2pdf blank.ps blank.pdf
# get number of pages of $source
num=$(pdftk "$source" dump_data | grep -Po 'NumberOfPages: \K.*')
# create string with new page numbers
for ((i=1;i<=$num;i++)); do pages="$pages A$i-$i B1-1"; done
# create pdf with white pages
pdftk A="$source" B=blank.pdf cat $pages output tmp.pdf
# create pdf with two pages on one side
pdfjam tmp.pdf --nup 2x1 --landscape --outfile "$output"
# clean up
rm blank.ps blank.pdf tmp.pdf
I have a solution which does not print exactly the layout which you want, but prints the page centered in the landscape sheet, like so:
+---+-------+----+
| | P.1 | |
| | | |
| | | |
+---+-------+----+
+---+-------+----+
| | P.2 | |
| | | |
| | | |
+---+-------+----+
If you're goal is to create free space for hand annotations, this layout might be better since it lets you write the annotation closer to the printed text.
The following script relies on pdfjam which uses LaTeX under the hood. Probably adding a few more command line arguments for pdfjam would get exactly what you are looking for.
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "usage: $0 PDF_filename..."
echo
echo "This script takes a PDF file as command line arguments,"
echo "and generates a new, landscape-formatted PDF file, where every "
echo "page has very large margins which may be useful for editorial notes"
echo
echo "Requires: pdfjam, which is installed by the apt-get package texlive-extra-utils"
exit 1
fi
command -v pdfjam >/dev/null 2>&1 || { echo >&2 "I require pdfjam but it's not installed. Do an apt install of texlive-extra-utils to get it on Ubuntu. Aborting."; exit 1; }
pdfjam --batch --nup 1x1 --suffix widemargin --landscape "$#"

Get Macbook screen size from terminal/bash

Does anyone know of any possible way to determine or glean this information from the terminal (in order to use in a bash shell script)?
On my Macbook Air, via the GUI I can go to "About this mac" > "Displays" and it tells me:
Built-in Display, 13-inch (1440 x 900)
I can get the screen resolution from the system_profiler command, but not the "13-inch" bit.
I've also tried with ioreg without success. Calculating the screen size from the resolution is not accurate, as this can be changed by the user.
Has anyone managed to achieve this?
I think you could only get the display model-name which holds a reference to the size:
ioreg -lw0 | grep "IODisplayEDID" | sed "/[^<]*</s///" | xxd -p -r | strings -6 | grep '^LSN\|^LP'
will output something like:
LP154WT1-SJE1
which depends on the display manufacturer. But as you can see the first three numbers in this model name string imply the display-size: 154 == 15.4''
EDIT
Found a neat solution but it requires an internet connection:
curl -s http://support-sp.apple.com/sp/product?cc=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | cut -c 9-` |
sed 's|.*<configCode>\(.*\)</configCode>.*|\1|'
hope that helps
The next script:
model=$(system_profiler SPHardwareDataType | \
/usr/bin/perl -MLWP::Simple -MXML::Simple -lane '$c=substr($F[3],8)if/Serial/}{
print XMLin(get(q{http://support-sp.apple.com/sp/product?cc=}.$c))->{configCode}')
echo "$model"
will print for example:
MacBook Pro (13-inch, Mid 2010)
Or the same without perl but more command forking:
model=$(curl -s http://support-sp.apple.com/sp/product?cc=$(system_profiler SPHardwareDataType | sed -n '/Serial/s/.*: \(........\)\(.*\)$/\2/p')|sed 's:.*<configCode>\(.*\)</configCode>.*:\1:')
echo "$model"
It is fetched online from apple site by serial number, so you need internet connection.
I've found that there seem to be several different Apple URLs for checking this info. Some of them seem to work for some serial numbers, and others for other machines.
e.g:
https://selfsolve.apple.com/wcResults.do?sn=$Serial&Continue=Continue&num=0
https://selfsolve.apple.com/RegisterProduct.do?productRegister=Y&country=USA&id=$Serial
http://support-sp.apple.com/sp/product?cc=$serial (last 4 digits)
https://selfsolve.apple.com/agreementWarrantyDynamic.do
However, the first two URLs are the ones that seem to work for me. Maybe it's because the machines I'm looking up are in the UK and not the US, or maybe it's due to their age?
Anyway, due to not having much luck with curl on the command line (The Apple sites redirect, sometimes several times to alternative URLs, and the -L option doesn't seem to help), my solution was to bosh together a (rather messy) PHP script that uses PHP cURL to check the serials against both URLs, and then does some regex trickery to report the info I need.
Once on my web server, I can now curl it from the terminal command line and it's bringing back decent results 100% of the time.
I'm a PHP novice so I won't embarrass myself by posting the script up in it's current state, but if anyone's interested I'd be happy to tidy it up and share it on here (though admittedly it's a rather long winded solution to what should be a very simple query).
This info really should be simply made available in system_profiler. As it's available through System Information.app, I can't see a reason why not.
Hi there for my bash script , under GNU/Linux : I make the follow to save
# Resolution Fix
echo `xrandr --current | grep current | awk '{print $8}'` >> /tmp/width
echo `xrandr --current | grep current | awk '{print $10}'` >> /tmp/height
cat /tmp/height | sed -i 's/,//g' /tmp/height
WIDTH=$(cat /tmp/width)
HEIGHT=$(cat /tmp/height)
rm /tmp/width /tmp/height
echo "$WIDTH"'x'"$HEIGHT" >> /tmp/Resolution
Resolution=$(cat /tmp/Resolution)
rm /tmp/Resolution
# Resolution Fix
and the follow in the same script for restore after exit from some app / game
in some S.O
This its execute command directly
ResolutionRestore=$(xrandr -s $Resolution)
But if dont execute call the variable with this to execute the varible content
$($ResolutionRestore)
And the another way you can try its with the follow for example
RESOLUTION=$(xdpyinfo | grep -i dimensions: | sed 's/[^0-9]*pixels.*(.*).*//' | sed 's/[^0-9x]*//')
VRES=$(echo $RESOLUTION | sed 's/.*x//')
HRES=$(echo $RESOLUTION | sed 's/x.*//')

Ditaa not aligning

It should be clear to know (for a human) what I want this ditaa-input file to look like
/---------------------------\
| TEST |
+--------------+------------+
| foo() | "yuck < 3" |
+--------------+------------+
| bar() | NEVEREVER! |
+--------------+------------+
| antlioneater | (x>5) || d |
\--------------+------------/
But it doesn't. Look at the less/greater signs. Plus, that is one out-of-shape antlioneater!
What am I doing wrong? I invoked ditaa v0.9 as ditaa -E -e utf8 test.txt.
I suggest using another character that looks like it, for example ‹ and ›.
It's a bit of a trick, but since the output of ditaa is an image anyway, having a visually similar character is usually good enough.
I personally use this to embed HTML markup in my ditaa charts.
Ditaa parses > and < as arrow heads even if they are not attached to a line ( --> ), hence the weird rendering. It's unfortunate, but that's how it is!

Resources