I have these excel files in a user directory:
430_XFRtoDML.xlsx
431_XFRtoDML.xlsx
440_XFRtoDML.xlsx
450_XFRtoDML.xlsx
451_XFRtoDML.xlsx
465_XFRtoDML.xlsx
500_XFRtoDML.xlsx
Path: /home/user
I want to write a script to create a text file bit_list.txt
mentined below. It should remove the xlsx extension followed by :5.
and first 3 number from that file. e.g. 430_XFRtoDML:5. 430
filenames=`ls *.xlsx`
for eachfile in $filenames
do
echo $eachfile
done
Expected output:
$ cat bit_list.txt
430_XFRtoDML:5. 430
431_XFRtoDML:5. 431
440_XFRtoDML:5. 440
450_XFRtoDML:5. 450
451_XFRtoDML:5. 451
465_XFRtoDML:5. 465
500_XFRtoDML:5. 500
ls
--> https://unix.stackexchange.com/questions/128985/why-not-parse-ls-and-what-to-do-instead – pLumo Jan 19 '22 at 09:14rename 's/(...)(_XFRto_DML)\.xlsx/$1$2:5. $1/ *
– Henrik supports the community Jan 19 '22 at 09:15perl -le 'BEGIN { opendir $a, "." } while (readdir $a) { s/(...)(_XFRto_DML)\.xlsx/$1$2:5. $1/; print; }'
– Henrik supports the community Jan 19 '22 at 09:29