echo file names in reverse order [duplicate] - bash

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

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

Bash: adding a key/value pair to an existing config file [duplicate]

This question already has answers here:
How to append output to the end of a text file
(13 answers)
Closed 8 months ago.
I have an existing config config.ini file with the following content:
VALUE_A=a
VALUE_B=b
Using Bash, I'd like to add a new key-value pair VALUE_C=c to get the following:
VALUE_A=a
VALUE_B=b
VALUE_C=c
Is there a concise way to do this with Bash (ideally a one liner)?
As suggested in the comments, the answer is simply:
echo VALUE_C=c >> config.ini

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.

How to iterate over pairs of files with corresponding names in Bash [duplicate]

This question already has answers here:
Looping over pairs of values in bash [duplicate]
(6 answers)
Closed 3 years ago.
I have a folder with test cases named like test_1_in, test_1_out,
test_2_in, test_2_out etc. I want to write a script, that can test my program with these pairs, I suppose it would do something like this in a loop
diff <($program < $test_in) <($test_out)
So the question is what is the best way to do it in Bash? How to iterate through the pairs of files? And also how to capture exception, that is print some error message if diff shows some difference?
Iterate over *_in, and generate *_out using parameter expansions:
for test_in in test_*_in; do
test_out="${test_in%_*}_out"
if diff <("$program" "$test_in") "$test_out"; then
echo "$test_in failed."
fi
done

Resources