New answers tagged

0

With GNU awk (gawk) one my specify array traversals: awk -F'/' 'BEGIN {PROCINFO["sorted_in"] = "@ind_str_asc"} { a[$NF]=$0 } END { for ( i in a ) { print a[i] } }' files.txt In that case: load data into array, indices are defined by the last /-separated field (i.e. filename), elements are the lines of the file. ...


3

$ awk -F '/' '{ printf "%s/%s\n", $NF, $0 }' files.txt | sort | cut -d '/' -f 2- ./COPYRIGHT.txt ./MAINTAINERS.txt ./README.txt ./themes/seven/images/arrow-desc.png ./themes/seven/images/arrow-prev.png ./themes/seven/images/fc-rtl.png ./themes/seven/ie7.css ./themes/seven/images/list-item-rtl.png ./update.php ./web.config ./xmlrpc.php This ...


0

If you can only choose a suffix of a file name, and you want to display a path starting from the root directory, using a sufficient amount of ../ is the only way. There's no way to "restart" a path from the root directory midway. There's also no way to to refer to a home directory in a file, so you need to use something like ../../../../../home/...


1

You can write a plugin to support this. Some python knowledge is required though. See the sample plugin_new_sorting_method.py on how to define a new sorting method. And check out directory.py how the standard algorithms were implemented, e.g. def sort_by_basename(path): """returns path.relative_path (for sorting)""" ...


4

(Assuming you want to perform the same operation on all files in the current directory...) To replace + with _ : mmv '*+*' '#1_#2' To strip + : mmv '*+*' '#1#2' Now, mmv only replaces the first matching + for each file. If you are doing this manually from the shell, and only want/need to do this renaming process once, then you can just repeat the command ...


0

The standard POSIX sh shell allows us to write patterns like ./*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].csv and ./*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_imp.csv These would match the files you're interested in, in the current directory. (You could make these more specific, obviously, like ./*20[0-2][0-9][01][0-9][0-3][0-9].csv, which would still allow ...


1

With GNU Parallel: ls | parallel mv {} '{= s/(.*)\d{8}/${1}20210131/ =}' Tested on: this_123456789_file_19991231_some.thing You can include GNU Parallel directly in the script, if you do not have permission to install software on the system you will be running on: parallel --embed > newscript.sh


1

You can loop over the files in folder_A and for each one check whether the corresponding directory exists in folder_B. Parameter expansion can help you remove the .txt extension and the path. for f in folder_A/*.txt ; do d=${f%.txt} # Remove .txt at the end. d=folder_B/${d##*/} # Remove everything before the last /. if [[ -d $d ]] ; ...


0

One way to rename the files isvto first select the files using find utility abd then pass them onto sed which will construct the new name and tgen pass a pair to xargs to call mv command to do the renaming. d0=19710110 d8=$(seq -f '[0-9%g]' 8 | paste -sd'\0') find . -maxdepth 1 -type f \( -name "*_${d8}_imp.csv" -o -name "*_$d8.csv" \) -...


0

With bash you can split the filenames apart and reassemble them #!/bin/bash new="20201231" for file in *.csv do # Split the filename into its consituent parts if [[ "$a" =~ (.*)[0-9]{8}(_imp)?(\.csv)$ ]] then # Assemble a new filename dest="${BASH_REMATCH[1]}${new}${BASH_REMATCH[2]}${BASH_REMATCH[3]}"...


0

cat *.seq/PANS_1_2*.fasta > xyz already concatenates all fasta files. The for loop multiplies that by the number of seq files.


3

The problem is that rsync is trying to create directories in a NTFS partition with illegal characters. From Naming Conventions Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following: The following reserved characters: > (less than) < (...


0

Current answers answer the specific case in the question body, but for the case of deleting all other files, I combined Stéphane Chazelas's answer with this answer on excluding glob matches: shopt -s extglob for f in *.jpeg; do [ -e "$f" ] && echo rm -- "${f%.*}".!(jpeg) done


1

Rockallite gave a good answer, but I didn't want to type that every time. I made a reusable bash function to do this called "file2url". To see where to save bash functions, take a look at this thread on SO. file2url () { python -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< $1 } This assumes ...


Top 50 recent answers are included