How to recursively find all ipynb files in a directory, and why does my bash code fail
#!/bin/bash
directory= /Users/sakshamgupta/Downloads/Automation-TCN/Data
for var in $(find $directory -type f -name "*.ipynb")
do
echo "${var:2}"
done
I am trying to read all ipynb files in a directory and subdirectory. The script gives the error below
./convert-ipynb-py.bash: line 3: /Users/sakshamgupta/Downloads/Automation-TCN/Data: is a directory
find: illegal option -- t
do you know?
how many words do you know
See also questions close to this topic
-
How to raise error in bash if a dir does not match certain permissions?
How can I raise an error in bash if a directory at some path does not match the below permissions?
u=rwX,g=rwX,o=rwX
-
How to sort a specified column in l、Linux
This is my two column sequence, I want to combine them into 1 column and sort them in Linux, but I don't know how to write the shell script to handle them.
GGCTGCAGCTAACAGGTGA TACTCGGGGAGCTGCGG CCTCTGGCTCGCAGGTCATGGC CAGCGTCTTGCGCTCCT GCTGCAGCTACATGGTGTCG CGCTCCGCTTCTCTCTACG
The sorted results are as follows (first column first, second column second, and split by "\t")
1 GGCTGCAGCTAACAGGTGA 2 CCTCTGGCTCGCAGGTCATGGC 3 GCTGCAGCTACATGGTGTCG 4 TACTCGGGGAGCTGCGG 5 CAGCGTCTTGCGCTCCT 6 CGCTCCGCTTCTCTCTACG
what should I do?
-
Update global variable from while loop
Having trouble updating my global variable in this shell script. I have read that the variables inside the loops run on a sub shell. Can someone clarify how this works and what steps I should take.
USER_NonRecursiveSum=0.0 while [ $lineCount -le $(($USER_Num)) ] do thisTime="$STimeDuration.$NTimeDuration" USER_NonRecursiveSum=`echo "$USER_NonRecursiveSum + $thisTime" | bc` done
- Broken project in XCODE objective c
-
Can I use Xcode font on QtCreator?
After using QtCreator for a long time on Windows I was comfortable with it. But now I'm using it on macOS too and it feels different.
I noticed default font is different on macOS. And Xcode font perhaps looks better.
How can I use Xcode font on QtCreator on macOS?
-
OSX + Java + OpenSSL + org.apache.commons:commons-crypto = SegFault in OpenSslNative:initIDs
I had a simple Java class using Apache:commons-crypto to do encryption/decryption that was SegFaulting on me.
On OSX, I used Homebrew to install the latest OpenSSL to use.
Tracing down the issue, it occurred in the OpenSslNative:initIDs JNI linked native code somewhere. I found the c code here:
https://github.com/apache/commons-crypto/blob/master/src/main/native/org/apache/commons/crypto/cipher/OpenSslNative.c
https://github.com/apache/commons-crypto/blob/master/lib/include/config.h
Scanning through the code, I found that on OSX, the "libcrypto.dylib" is referenced. That library was correctly linked into the /usr/local/opt/openssl/lib directory.
-
Sytax error: Missing ), but I don't see it. My quotation marks don't seem to be the problem either
I've been working on this app script trying to automate data from a Google sheet to create events on Google Calendar. I've tried changing the Quotation marks from single to double and back. I've checked my () over and over. I cannot see what I've done that gives me the syntax error. If you can see it, please tell me. This is making me nuts.
function AutomateCalendarEvent() { let sheet = SpreadsheetApp.getActiveSheet(); let pqCalendar = CalendarApp.getCalendarById("zyxwvutsrqp"); let reservation = sheet.getRange("C2:E1105").getValues(); reservation.splice(0, 1); let rows = sheet.getDataRange().getValues(); rows.forEach(function (row, index) { if (index === 0) return; if (row[C3]) return; pqCalendar.createAllDayEvent("Last Name"C2:C, "Arrival Date"D2:D, "Departure Date"E2:E); }) }
-
Why are there three program control structures? Not more or less?
There are three program control structures. Sequence, selection, repetition structure. But why is there three? Not more or less? Or, are there more?
-
Exotic 2D array element referencing
I saw an exotic array element referencing in a C++ example:
int mat[2][2] = {{1,2},{3,5}}; cout << 0[1[mat]]; //<- what's this? // it means: // cout << mat[1][0];
Where is defined this syntax? I didn't learn it, nowhere in C and C++ books.
-
Linux find xargs command grep showing path and filename
find /folder/202205??/ -type f | xargs head -50| grep '^Starting'
There are 20220501 20220502 20220503 and so on folders... This command searches all first 50 lines of all files in '/folder/202205??/' and shows the lines beginning with text "Starting"
I haven't the path and the filename of the files that are matched by the grep command. How can I get this information: path and filename and the matched line with a simple command?
-
Recursively find files with a specific extension and copy them to a new directory with new names
I tried to find all the .xvg files generated by Gromacs inside a directory as well as its subdirectories and then copy them to a new directory, with new names for each file (the rule for naming is 'original path + name').
I used the following commands:
find . -type f -iname '*.xvg' -exec sh -c ' path="${1%/*}"; filename="${1##*/}"; echo cp "${1}" "test0605/${path##*/}_${filename}" ' sh_cp {} \;
The terminal seemed to work properly:
$ find . -type f -iname '*.xvg' -exec sh -c ' path="${1%/*}"; filename="${1##*/}"; echo cp "${1}" "test0605/${path##*/}_${filename}" ' sh_cp {} \; cp ./Loop2/Replica5/rmsf_10ns.xvg test0605/Replica5_rmsf_10ns.xvg cp ./Loop2/Replica5/rmsd.xvg test0605/Replica5_rmsd.xvg cp ./Loop2/Replica5/gyrate.xvg test0605/Replica5_gyrate.xvg cp ./Loop2/Replica4/rmsf_10ns.xvg test0605/Replica4_rmsf_10ns.xvg cp ./Loop2/Replica4/rmsd.xvg test0605/Replica4_rmsd.xvg cp ./Loop2/Replica4/gyrate.xvg test0605/Replica4_gyrate.xvg cp ./Fab_fMD_ff15_n160_10ns/rmsf_10ns.xvg test0605/Fab_fMD_ff15_n160_10ns_rmsf_10ns.xvg cp ./Fab_fMD_ff15_n160_10ns/rmsd.xvg test0605/Fab_fMD_ff15_n160_10ns_rmsd.xvg cp ./Fab_fMD_ff15_n160_10ns/gyrate.xvg test0605/Fab_fMD_ff15_n160_10ns_gyrate.xvg cp ./Loop1/Replica1/rmsf_10ns.xvg test0605/Replica1_rmsf_10ns.xvg cp ./Loop1/Replica1/rmsd.xvg test0605/Replica1_rmsd.xvg cp ./Loop1/Replica1/gyrate.xvg test0605/Replica1_gyrate.xvg cp ./Loop1/Replica2/rmsf_10ns.xvg test0605/Replica2_rmsf_10ns.xvg cp ./Loop1/Replica2/rmsd.xvg test0605/Replica2_rmsd.xvg cp ./Loop1/Replica2/gyrate.xvg test0605/Replica2_gyrate.xvg cp ./Loop1/Replica3/rmsf_10ns.xvg test0605/Replica3_rmsf_10ns.xvg cp ./Loop1/Replica3/rmsd.xvg test0605/Replica3_rmsd.xvg cp ./Loop1/Replica3/gyrate.xvg test0605/Replica3_gyrate.xvg
However, when I opened the
test0605
folder it was empty inside, with no files actually being copied into it. So I was just wondering if anyone happens to know the reason.Many thanks.
-
Find item in a Linked List in C
Following the tutorial, I wrote down this function to find the key in a linked list. However, it doesn't seem to work for me, curious about the reason. Here's part of the find function:
node_t *find_node(node_t *head, int number_to_find) { node_t *tmp = head; while (tmp != NULL) { if(tmp->value == number_to_find) { return tmp; tmp = tmp->next; } } return NULL; }
I embedded this function into my program. It successfully compiled but as it runs, the terminal did not show anything.
#define MAX_LIST 25 typedef struct node { int value; struct node *next; }node_t; node_t *create_new_node(int value) { node_t *new = malloc(sizeof(node_t)); new->value = value; new->next = NULL; return new; } node_t *add_to_list(node_t *head, node_t *next_node) { next_node->next = head; return next_node; } /* TO FIND VALUE IN THE LINKED LIST */ node_t *find_link_list(node_t *head, int number_to_find) { node_t *tmp = head; while (tmp != NULL) { if(tmp->value == number_to_find) { return tmp; tmp = tmp->next; } } return NULL; } bool print_linked_list(node_t *head) { if(head == NULL) { return false; } else { node_t *tmp = head; while(tmp != NULL) { printf("%d ", tmp->value); tmp = tmp->next; } return true; } } int main() { node_t *head = NULL; node_t *tmp; for(int i = 0; i < MAX_LIST; i++) { tmp = create_new_node(i); head = add_to_list(head, tmp); } tmp = find_link_list(head, 9); printf("%d \n", tmp->value); print_linked_list(head); }
Anyone has a clue why this happen? It would be much appreciated : )