
ls:ai:561ba
List all pdf files inside directory then print on scren each filename in alphabetical order, adding "_num" before the extension, where "num" is a 3-digit counter starting from 001
$ ls | grep .pdf | awk '{print $0, "_" sprintf("%03d", NR) }' | sort | awk '{print "{\"filename\": \""$1"\"}"}' | sed ':a;N;$!ba;s/\n/,\n/g'
try on your machine
This command lists all the PDF files in the current directory, adds the counter to each filename in alphabetical order, and converts the output into a JSON string with the field name 'filename'.
This explanation was created by an AI. In most cases those are correct. But please always be careful and
never run a command you are not sure if it is safe.
Questions that are answered by this command:
- List all pdf files inside directory then print on scren each filename in alphabetical order, adding "_num" before the extension, where "num" is a 3-digit counter starting from 001?