tôba wrote: > Hello, > > Can you help me with a bash command? > I a directory, I want to extract with a command line for jpg name files. > I have a lot of: > > icon_3620_0_1.jpg > icon_3616_0_1.jpg > icon_3563_0_1.jpg > > I want to extract the number betwen icon_*_0_1.jpg AND I want to use > the entire filename too in the same command. > > The goal is to create a directory called 3620 and move the > icon_3620_0_1.jpg file into this directory. > > So, I did like this for test: > > # for a in `ls | sed -e s'/_/ /g' | awk '{print $2}'`; do echo > icon_$a_0_1.jpg; done > > I hope it should give me: > > icon_3620_0_1.jpg > icon_3616_0_1.jpg > icon_3563_0_1.jpg > > like the original > > BUT in my surprise, it shows: > > icon_.jpg > icon_.jpg > icon_.jpg > icon_.jpg > > Why? > Where is the $a_0_1 gone? Surely I missed something but I cannot > find it. > Can you tell me how to reproduce the exact filename so? > > Best regards, > > -- > Tôba > >
Hello, do you means like that? for a in `ls | sed -e s'/_/ /g' | awk '{print $2}'`; do echo icon_${a}_0_1.jpg; done A better way maybe is: [EMAIL PROTECTED]:~/test/jpg$ touch icon_3563_0_1.jpg icon_3616_0_1.jpg icon_3620_0_1.jpg [EMAIL PROTECTED]:~/test/jpg$ ls icon_3563_0_1.jpg icon_3616_0_1.jpg icon_3620_0_1.jpg [EMAIL PROTECTED]:~/test/jpg$ ls | awk -F_ '{print $2}' 3563 3616 3620 [EMAIL PROTECTED]:~/test/jpg$ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]