sh

looping object as inputs in BASH, SHELL script

时光总嘲笑我的痴心妄想 提交于 2019-12-13 03:03:12
问题 multiple files with the same name grid_200001.grb2.nc with only one components changing and that is the month grid_200010.grb2.nc . I would like to use them all simultaneously as input files An example of what I am hoping to achieve is fname="grid_" year="2010" month="01 02 03 04 05 06 07 08 09 10" ext="grb2" end="nc" for((y=$year;y<=$year;y++)); do for m in $month do ifile=$fname$y$m.$ext.$end >>merge $ifile $ifile ... ofile example of the desired command i would like to have is >> merge

Bash script to replace all occurrences of string in files, including filenames

白昼怎懂夜的黑 提交于 2019-12-13 02:55:40
问题 I want to be able to replace the occurrences of one string with another in the file contents and filenames of all files within a directory minus the ".git" directory. I have the following code, which is good for changing the filenames but doesn't replace strings inside the files. What am I doing wrong? #!/bin/bash # Replace occurances in files, lowercase lower1=$(echo $1 | tr '[:upper:]' '[:lower:]') lower2=$(echo $2 | tr '[:upper:]' '[:lower:]') echo "Replacing $lower1 with $lower2..." find

Find files with extension with 5 characters or more

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 01:43:26
问题 I have a lot of residue files from a failed rsync-command. They all have a file extension of 5 (random)characters. Is there a command that can find all files with an extension of 4 characters and more recursively? Example of a rsync residue filename: foo.jpg.hzmkjt7 I've already found out a way to prevent this with rsync, but all I need to do now is clean those leftovers... 回答1: Using bash, one option would be to use globstar like this: shopt -s globstar # enable the shell option echo **/*.??

Expanding the PATH with a list of directories extracted from a text file, the '~' character not expanded to HOME

为君一笑 提交于 2019-12-13 01:42:45
问题 The PATH is expanded by a list of directories extracted from a text file; $ cat ~/.path ~/.local/bin ~/W-space/esp/esp-open-sdk/xtensa-lx106-elf/bin ~/W-space/research/recognition/voxforge/bin ~/W-space/research/recognition/voxforge/bin/julius-4.3.1/bin like so (The following can be found in one of the BASH's startup files): declare -a BATH_ARRAY=($(cat ~/.path)) 2>/dev/null # extend path for BATH in "${BATH_ARRAY[@]}" do case ":${PATH}:" in *:${BATH}:*) ;; *) PATH=${PATH}:$BATH && export

Running bash script via Node.js - Illegal option -o pipefail

我的未来我决定 提交于 2019-12-13 01:24:34
问题 I am trying to exec a bash script via Node.js using child_process.exec() . However it is blowing up on the second line of the file: #!/usr/bin/env bash set -eo pipefail; [[ $TRACE ]] && set -x echo "we are here" The error returned is: /bin/sh: 2: set: Illegal option -o pipefail Why is this happening? When I run the script manually, not from Node it works fine. Here is the Node.js code: var child = child_proc.exec(bashScript, { env: _.extend(process.env, { 'LB_HOST': config.loadBalancers.lb1 }

Difference of Time between two lines of a log file

时光怂恿深爱的人放手 提交于 2019-12-12 22:14:46
问题 My apologies if this is too basic. I'm really not looking for someone to do the work but rather point me in the right direction. I have a log files going back several years that I want to pull information out to determine how long something is taking to look for patterns on when performance is slow. I am able to read each line but cannot read the previous line to get its time. The Log files are as follows: ~ Other Stuff ~ 12/21/11 18:58:15 Inserting data into ST_ITEMS ST_ITEMS Row: 10000

What does tr -d [=,=] do?

六眼飞鱼酱① 提交于 2019-12-12 21:24:25
问题 I have a code example and there seems to be a piece of extra formatting tacked onto the end of some text processing: tr -d [=,=] I don't know what this does and the man page for tr is of little help. Any insight on what this does? 回答1: From the man tr page, [=equiv=] Equivalence classes The syntax [=C=] expands to all of the characters that are equivalent to C , in no particular order. Equivalence classes are a relatively recent invention intended to support non-English alphabets. But there

Script that will transfer photos from phone camera using adb

旧巷老猫 提交于 2019-12-12 21:02:05
问题 Story I take photos and record videos with my phone camera and keep all of them on my internal storage/sdcard. I periodically back them up on my PC, so I keep these camera photos on PC storage in sync with phone storage. For years, I've been backing up my phone camera photos to my PC in the following way: Plug in phone into PC and allow access to phone data Browse phone storage → DCIM → Camera Wait several minutes for the system to load a list of ALL photos Copy only several latest photos

Portability between Unix shells - am I thinking about the issue correctly?

痴心易碎 提交于 2019-12-12 18:11:55
问题 Whenever I write shell scripts (mostly software development utilities or build tools) I've generally tried to avoid using bash in favor of using plain old sh for portability. However lately I've been running into more and more issues where useful features are not available, or behavior is actually less consistent across systems using sh then it is using bash, since sh is aliased to different shells... As I understand it, sh is the oldest Unix shell and carefully written sh scripts should in

awk script needs revision or possibly grep solution (new to awk)

為{幸葍}努か 提交于 2019-12-12 17:19:40
问题 I have a dataset like I have linked here: http://pastebin.com/7tpBAqua Note the first two lines are not data(numbers), despite this, the 2nd line is associated with the 3rd line. Similarly, the 4th line is associated with the 5th line, and so on. Currently, we have an awk script that outputs info on all line numbers that were above the threshold value (anything below -1 and above 1), this is the output: 71 72 88 98 99 .... and so on... If the number is even we need to output the number that