find only the first file from many directories

I have a lot of directories: 13R 613 AB1 ACT AMB ANI Each directories contains a lots of file: 20140828.13R.file.csv.gz 20140829.13R.file.csv.gz 20140830.13R.file.csv.gz 20140831.13R.file.csv.gz 20140901.13R.file.csv.gz 20131114.613.file.csv.gz ...
more »

2017-02-15 16:02 (2) Answers

Start a line in bash script with !! (double bang)

How would I start a line in a bash/shell script with a double bang in order for the last input to be run again? I want to pipe the past output of the last run program into a new program. For example, if I ran ls -l last, and now i run this script, ...
more »

2017-02-12 22:02 (1) Answers

Sanitize $PATH for find -execdir

find -execdir is recommended over -exec, which the manual says has unavoidable security issues, and lists in the bugs section. man find says regarding -execdir: If you use this option, you must ensure that your $PATH environme...
more »

2017-02-12 09:02 (1) Answers

Trying to print a part of each line in sed

I'm trying to use sed to print just the last part of the url from a list of data. I want it to be using sed not awk. Input data is like this: Place,AF,http://en.wikipedia.org/wiki/Benin Place Mat,NA,http://en.wikipedia.org/wiki/Saint_Barthelemy Ori...
more »

2017-02-11 10:02 (1) Answers

Reassigning awk array during loop

My problem is the following: I had a text file formatted in a way: 12 apple 78 orange 12 prune 12 prune 78 berries 78 cake What I needed is to reassign the values in a form: 12 apple, prune 78 orange, berries, cake I did it using awk {sbj=$...
more »

2017-02-10 15:02 (2) Answers

grep with continuous pipe does not work

(maybe it is the "tcpflow" problem) I write a script to monitoring http traffic, and I install tcpflow, then grep it works (and you should make a http request, for example curl www.163.com) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | grep ...
more »

2017-02-10 12:02 (2) Answers

macOS Sierra 10.12.2 mv: No such file or directory

I'm trying to rename a bunch of files and folders with a script, recursively. This is the bash script #!/bin/bash TMP="NEW" cd tmp find . -depth \( -type f -o -type d \) -name "*tmp*" \ -execdir env "NEW_NAME=$TMP" bash -c \ 'for file do mv -- "$f...
more »

2017-02-08 12:02 (0) Answers

When do I set IFS to a newline in Bash?

I thought setting IFS to $'\n' would help me in reading an entire file into an array, as in: IFS=$'\n' read -r -a array < file However, the above command only reads the first line of the file into the first element of the array, and nothing els...
more »

2017-02-06 06:02 (2) Answers

Using variables as the input to command

I've scoured various message boards to understand why I can't use a variable as input to a command in certain scenarios. Is it a STDIN issue/limitation? Why does using echo and here strings fix the problem? For example, ~$ myvar=$(ls -l) ~$ grep J...
more »

2017-02-05 16:02 (3) Answers

Bash-based Hot Reload Implementation

tl;dr version Question: How to make a bash script / command to listen to changes to a file and then output the result of a specific Bash command? Long version Real Scenario: I am refactoring a Perl module (my_module.pm) and I have a test file which ...
more »

2017-02-05 09:02 (2) Answers

bash `read -t` doesn't work on pipe

A very simple way to demonstrate this is to run mkfifo /tmp/a read -t 1 a < /tmp/a the read never return. Bash Manual says: This option is only effective if read is reading input from a terminal, pipe, or other special file; it has no...
more »

2017-02-04 15:02 (1) Answers

Avoid collision, if copying files

I was trying to copy all files of a certain filetype from all subfolders to one place. Unfortunately, this might cause collisions, if two files have the same name from two different subfolders. I was using find ./ -name '*.jpg' -exec mv -u '{}' . ...
more »

2017-02-04 00:02 (1) Answers

Merge Arrays of JSON

So my objective is to merge json files obtain this format: { "title": "NamesBook", "list": [ { "name": "Ajay" }, { "name": "Al" } ] } And I have files that look like this format: blahblah.json { "title": "Name...
more »

2017-02-02 20:02 (3) Answers

Redirecting stdout to file shows wrong content

I have a named pipe 'timer_fifo', stdout of a python script is redirected to timer_fifo while parallely another shell script process reads from it, processes it then redirects it to another file named 'activity_file'. Python Script: import time whi...
more »

2017-02-02 08:02 (1) Answers

How to mirror local tags to remote

There are hundreds of Git tag questions on SO, but I couldn't find this one. How can I mirror my local git tags to remote. That is: No matter what the original status of origin I'd like to have a bash function which mirrors all local tags to the ...
more »

2017-02-01 05:02 (1) Answers

bash use output of find with grep

I'm trying to grep a pattern in an unknown file in a directory that has a lot of files. I'd normally execute the following code: $ grep 0RY7HYLA in ./*8017*/*diag* However because I'm searching for files in a very large folder of files I can't use...
more »

2017-01-30 15:01 (1) Answers