software:unixtools [PaleoEarthLabs wiki]

PaleoEarthLabs wiki

One bucket of limited wisdom

Site Tools


software:unixtools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
software:unixtools [2019/02/11 20:17]
christian
software:unixtools [2020/06/27 22:29] (current)
chwikad [Unison]
Line 2: Line 2:
  
 A collection of quick-and-dirty tricks to do things with the standard command line tools in *Nix and cygwin. I am copying stuff here as I use these snippets regularly so this is a central repo for the ageing brain. A collection of quick-and-dirty tricks to do things with the standard command line tools in *Nix and cygwin. I am copying stuff here as I use these snippets regularly so this is a central repo for the ageing brain.
 +
 +===== Bash =====
 +
 +Loop through a list of data, providing special cases depending on input data.
 +
 +<code bash>
 +inData=( data1 data2 data3 )  # This generates an iterable list of items
 +for theData in  ${inData[*]};​ do
 +    case "​$theData"​ in
 + "​data1"​) ​
 +   inGrid="​$grid1"​
 +          cpt=
 + ;;
 + "​data2"​) ​
 +          inGrid="​$grid2"​
 +          cpt=
 + ;;
 +    esac
 +done
 +</​code>​
 +
 +  * Using ''​set -x''​ prints a ''​+''​ before each executed command in a bash script via [[https://​www.peterbe.com/​plog/​set-ex]]
 +
 +
  
 ===== AWK ===== ===== AWK =====
Line 33: Line 57:
  
 awk -v a="​$var1"​ -v b="​$var2"​ 'BEGIN {print a,b}' awk -v a="​$var1"​ -v b="​$var2"​ 'BEGIN {print a,b}'
 +</​code>​
  
 +
 +Convert a GMT file into a csv file which can be processed by ''​ogr2ogr'',​ meanwhile adding some attributes.
 +
 +<code awk>
 +awk -v url="​${someurl}"​ -v r="​$another"​ -v au="​$au"​ '​BEGIN{OFS=","​} {
 +  if (/^>/) split($5,​a,"​-"​) split($NF,​b,"​="​)
 +  else 
 +  printf("​%03d,​%s,​%s,​%s,​%s/​%s_MyOutput_%03d.png,​%s\n",​ a[3], $1, $2, b[2], url, r, a[3], au )}' ${v}/​${v}_somedata.dat >> tmp.csv
 </​code>​ </​code>​
  
Line 51: Line 84:
  
  
-{{tag> Unix awk command_line Quick_and_dirty}}+===== Interrogating EBDIC Headers of SEGY files ===== 
 + 
 +When trying to plot SEG-Y files with [[http://​generic-mapping-tools.org|GMT]] one needs to have knowledge about the data. Using Unix's ''​dd''​ command, one can interrogate the EBDIC header: 
 + 
 +<code bash> 
 + dd if=$1 conv=ascii ibs=3200 count=1 | awk '​BEGIN{RS="​C[0-9 ][0-9]"​}{printf "​C%2d%s\n",​NR,​$0}'​ 
 +</​code>​ 
 + 
 +Source: [[https://​hollyghozi.blogspot.com/​2006/​11/​oilgas-how-to-read-ebcdic-segy-header.html|hollyghozi.blogspot.com]] 
 + 
 +===== Image manipulation ===== 
 + 
 +Sometimes it is necessary to quickly manipulate an image sequence for movie generation etc. ImageMagick/​GraphicsMagick provide a command line based way to crop/​scale/​resize images. 
 + 
 +Cropping: 
 + 
 +<code bash> 
 + 
 +for i in *.jpg; do echo $i; magick $i -crop NewXwidthxNewYwidth+xoffset+yoffset ${i/​*.jpg/​*_mod.jpg/​};​ done 
 + 
 +</​code>​ 
 + 
 + 
 +===== Reset the shell ===== 
 + 
 +At some stage I accidentally used ``curl`` instead of ``wget`` resulting in a bunch of wild binary stuff being passed on to the shell, resetting the bash configuration. [[https://​unix.stackexchange.com/​questions/​302548/​hash-symbols-turned-into-pound-symbols-%C2%A3-after-catting-a-binary|Turns out that I am fortunately not alone]] and one can [[http://​man7.org/​linux/​man-pages/​man4/​console_codes.4.html|reset the console codes]] to their defaults using: 
 + 
 +    reset 
 +     
 +===== Unison ===== 
 + 
 +[[https://​www.cis.upenn.edu/​~bcpierce/​unison/​|Unison]] is a fantastic tool to synchronise directories on multiple computers, like a desktop or server and a laptop. I have been using Unison now for a couple of years after using  
 + 
 +It seems that some of the Apple Security Updates change/​alter the machine settings in places such as ''/​etc/​ssh/​ssh_config''​. This then results in unison (which is run over ''​ssh''​) then to complain that the path cannot be found. The remedy is make sure that in ''/​etc/​ssh/​sshd_config''​ (note the **d**!) the following parameter is set to: ''​PermitUserEnvironment yes''​ 
 + 
 + 
 + 
 + 
 + 
 + 
 + 
 + 
 + 
 +{{tag> Unix awk command_line Quick_and_dirty ​SEGY magick imageprocessing reset}}
software/unixtools.1549912676.txt.gz · Last modified: 2019/02/11 20:17 by christian