0

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

  • 2
    You can order the files using `ls`, e.g. `USER="vcp"; ls -r "${USER}"-status-* | xargs cat >> OutputFile`. Does that work for your use-case? – jared_mamrot Jul 26 '22 at 04:26
  • did you read the man page of ls? `ls --help` gives `Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.` and the `-r` option for reversing – phuclv Jul 26 '22 at 04:30
  • Thanks for the inputs, I would like to echo the list of files contents to a OutputFile. – VCP Muthukrishna Jul 26 '22 at 10:05
  • ls -r ${USER}-status-* | xargs cat >> OutPutFile worked. Thank you @jared_mamrot – VCP Muthukrishna Jul 27 '22 at 04:27
  • You're welcome; other options are covered in the linked posts ([How to reverse a list of words in a shell string?](https://stackoverflow.com/questions/27703776/how-to-reverse-a-list-of-words-in-a-shell-string) & [Unix's 'ls' sort by name](https://stackoverflow.com/questions/878249/unixs-ls-sort-by-name)) – jared_mamrot Jul 27 '22 at 04:29

0 Answers0