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?
Related
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
This question already has answers here:
How to reverse a list of words in a shell string?
(18 answers)
Sort 'ls' output by name
(13 answers)
Closed 7 months ago.
This post was edited and submitted for review 7 months ago and failed to reopen the post:
Duplicate This question has been answered, is not unique, and doesn’t differentiate itself from another question.
I would like to list files in reverse order, list of files listed are as below, the purpose is to echo all the file contents into another file.
vcp.status-200.txt
vcp-status-400.txt
vcp-status-500.txt
vcp-status-000.txt
I am currently running below command; echo will list all the files and xargs cat will append the content of these files into OutputFile.
echo *${USER}*status*.txt | xargs cat >> OutputFile
Current Output
vcp-status-000.txt vcp-status-200.txt vcp-status-400.txt vcp-status-500.txt
Intended Output
vcp-status-500.txt vcp-status-400.txt vcp-status-200.txt vcp-status-000.txt
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.
This question already has answers here:
Difference between single and double quotes in Bash
(7 answers)
Closed 4 years ago.
I am very new to this all and have used this website to help me find the answers i'm looking for.
I want to replace a line in multiple files across multiple directories. However I have struggled to do this.
I have created multiple directories 'path_{0..30}', each directory has the same 'input' file, and another file 'opt_path_rx_00i.xyz' where i corresponds to the directory that the file is in (i = {0..30}).
I need to be able to change one of the lines (line 7) in the input file, so that it changes with the directory that the input file is in (path_{0..30}). The line is:
pathfile opt_path_rx_00i.xyz
Where i corresponds to the directory that the file is in (i={0..30})
However, i'm struggling to do this using sed. I manage to change the line for each input file in the respective directories, but i'm unable to ensure that the number i changes with the directory. Instead, the input file in each directory just changes line 7 to:
pathfile opt_path_rx_00i.xyz
where i, in this case, is the letter i, and not the numbers {0..30}.
I'll show what i've done below in order to make more sense.
for i in {0..30}
do
sed -i '7s/.*/pathfile-opt_path_rx_00$i.xyz/' path_$i/input
done
What I want to happen is, for example in directory path_3, line 7 in the input file will be:
pathfile opt_path_rx_003.xyz
Any help would be much appreciated
can you try with double quotes
for i in {0..30}; do
sed -i "7s/.*/pathfile-opt_path_rx_00$i.xyz/" "path_$i/input"
done
This question already has answers here:
How to change a command line argument in Bash?
(3 answers)
How to compare timestamp on files in bash scripting
(3 answers)
Closed 5 years ago.
I often use exiftool to copy metadata from one file to another.
exiftool -TagsFromFile FILE1[SOURCE] FILE2[TARGET]
I am trying to speed up the workflow and figure out a bash script that would allow me to simply select two files in file explorer - right click on them - open with - thescript.sh
/path/to/thescript.sh $1 $2
As you can see the most important part is to select a right file as the source ($1) / target ($2).
Source files often named like this:
20170630_181348_2674.jpg or 20170630_181348_2674.dng
Target files usually have a suffix added to the name e.g. 20170630_181348_2674_0001.jpg or 20170630_181348_2674_v2.jpg
So one thing I know for sure is that the source file name is always shorter.
Another thing, the files I use as the source are always older than the ones I copy metadata to.
I was wondering if there is any way in bash to compare inputs ($#) by their file name or by the file modify date and place them as $1 and $2 accordingly.
Any ideas would be greatly appreciated.