Bash - Renaming episode names to remove junk [duplicate] - bash

This question already has answers here:
Rename files using a regex with bash [duplicate]
(4 answers)
bulk file renaming in bash, to remove name with spaces, leaving trailing digits
(3 answers)
Rename multiple files based on pattern in Unix
(24 answers)
Better way to rename files based on multiple patterns
(5 answers)
Closed 12 months ago.
When I am looking at episode names, often they're in the format of:
The.Show.Name.S06E01.lots.of.junk-often_with_chars.mkv
The.Show.Name.S06E02.lots.of.junk-often_with_chars.avi
Show.Name.S06E03.lots.of.junk-often_with_chars.mp4
I'd like to end up with a simple:
Show Name S06E01.mkv
Show Name S06E02.avi
Show Name S06E03.mp4
Ideas on a simple bash command or two I could run to clean up all the junk, remove the periods other than the end, allow for any three-digit file extension?
Thank you.

Related

for loop in shell script now working as expected [duplicate]

This question already has answers here:
How to match nothing if a file name glob has no matches [duplicate]
(2 answers)
How to skip the for loop when there are no matching files?
(2 answers)
Closed 3 days ago.
I have some output files like output1.bin, output2.bin and I need to add them to the list output_files. It works as expected when output files exists, but it adds "output*.bin" in the list variable if output1.bin, output2.bin does not exists. I expected that if "${outputdir}"/output*.bin doesn't match any file it should not even iterate through it i.e. I expeted the list to be empty but it adds output*bin name to it. Can someone explain the behavior and the fix ?
for bin_file in "${outputdir}"/output*.bin; do
output_files+=("${bin_file}")
done

grep names in a small file matching a large file [duplicate]

This question already has answers here:
Are shell scripts sensitive to encoding and line endings?
(14 answers)
grep not showing result which read id from file
(2 answers)
Closed 12 months ago.
My small file contains this information line by line:
abc.123
abc.258
abc.952
I wanted to get those lines matching in my bigger file (~30Gb). I tried this command but it didn't give me any result.
grep -f small.txt big.txt
I have tested all abc.123, abc.258 and abc.952 does exist in my bigger file, meaning that I tried to grep each of these names one by one it gave me the exact result I want.
grep "abc.123" big.txt
I have no idea where I could possibly go wrong?

Can we compress multiple .gz files to on gz file [duplicate]

This question already has answers here:
Pass list of arguments to a command in shell
(3 answers)
Fast Concatenation of Multiple GZip Files
(4 answers)
Closed 1 year ago.
I can combine .sdf.gz many files to single file like this
cat CAAAML.xaa.sdf.gz CAAAMM.xaa.sdf.gz CAAAMN.xaa.sdf.gz CAAAMO.xaa.sdf.gz CAAAMP.xaa.sdf.gz > all.sdf.gz
I make a list in the directory
ls > list
CAAAML.xaa.sdf.gz
CAAAMM.xaa.sdf.gz
CAAAMN.xaa.sdf.gz
CAAAMO.xaa.sdf.gz
CAAAMP.xaa.sdf.gz
CAAARL.xaa.sdf.gz
CAAARM.xaa.sdf.gz
CAAARN.xaa.sdf.gz
CAAARO.xaa.sdf.gz
CAAARP.xaa.sdf.gz
CAABML.xaa.sdf.gz
CAABMM.xaa.sdf.gz
CAABMN.xaa.sdf.gz
CAABMO.xaa.sdf.gz
CAABMP.xaa.sdf.gz
CAABRL.xaa.sdf.gz
CAABRM.xaa.sdf.gz
CAABRN.xaa.sdf.gz
CAABRO.xaa.sdf.gz
CAABRP.xaa.sdf.gz
how can i combine the files using list into one sdf.gz
Thanks for the response.

Bash: how to rename a file to a string containing forward slashes? [duplicate]

This question already has answers here:
Is it possible to use "/" in a filename?
(8 answers)
Closed 1 year ago.
I have a file that I want to rename to a date like "20/02/21", but if I do mv file.txt 20/02/21 it interprets the forward slashes as referencing sub-folders. Is there a way to do this?
No, there's no way to do it. On Unix forward slash / is used to
separate directories and cannot be used in the filename. You have to
use another delimiter - 20\02\21, 20-02-21, 20.02.21 etc.

Why does * put all file names in the argument vector? [duplicate]

This question already has answers here:
What is file globbing?
(1 answer)
Stop shell wildcard character expansion?
(4 answers)
command line * linux [duplicate]
(1 answer)
Closed 4 years ago.
I stumbled upon this while working through the exercises in K&R2. Why does echo * prints the names of all files in the current directory? More generally, when I write a C program that takes command-line arguments, and when I give it * as an argument, it puts the names of all files in its parent directory in to the argument vector. Why does this happen? What is so special about *?
I could not find anything about this in the internet.
This is called globbing. Here's a detailed description. Other wildcards include ? for one character, [abc] for one of a set of characters, and [a-z] for one of a range of characters. This is built into various shells, including Bash.
In response to your comment "I think echo is written in C" — this doesn't matter a bit. Once source code is compiled into an executable containing machine code, it doesn't matter what language it was written in.

Resources