Hey,
I'm trying to create a bash script to do the following;
example source files:
- a_b_c_qwer_e_123.xml
- a_b_c_rewq_e_abc.xml
- a_b_c_tyui_e_cba.xml
- a_b_c_iuyt_e_321.xml
- a_b_c_qazws_e_000.xml
- a_b_c_swzaq_e_333.xml
What i would like to do is extract the first part of a filename.
For example "a_b_c_qwer_e_123.xml" is the filename, what I need to extract is this part: "a_b_c_qwer_e" without the source filnames being renamed.
Then the following needs to be done. Based on the first part of the file, in this case "a_b_c_qwer_e", the file has to be copied to the directory "/a_b_c_qwer_e". So actually it's a (partly)filename based copy.
What I've created so far is the following...which sux due to I`m creating a lot of variables this way.
I searched on google but couldn't find a good result. Hope someone can help me out! Tx!
#!/bin/bash
QUEUE_01="a_b_c_qwer_e"
QUEUE_02="a_b_c_rewq_e"
QUEUE_03="a_b_c_tyui_e"
QUEUE_04="a_b_c_iuyt_e"
QUEUE_05="a_b_c_qazws_e"
QUEUE_06="a_b_c_swzaq_e"
ls -1 | while read file
do
cp $file $(echo $file | cut -f1 -d"_" ).$(echo $file | cut -f2 -d".")
done
I'm trying to create a bash script to do the following;
example source files:
- a_b_c_qwer_e_123.xml
- a_b_c_rewq_e_abc.xml
- a_b_c_tyui_e_cba.xml
- a_b_c_iuyt_e_321.xml
- a_b_c_qazws_e_000.xml
- a_b_c_swzaq_e_333.xml
What i would like to do is extract the first part of a filename.
For example "a_b_c_qwer_e_123.xml" is the filename, what I need to extract is this part: "a_b_c_qwer_e" without the source filnames being renamed.
Then the following needs to be done. Based on the first part of the file, in this case "a_b_c_qwer_e", the file has to be copied to the directory "/a_b_c_qwer_e". So actually it's a (partly)filename based copy.
What I've created so far is the following...which sux due to I`m creating a lot of variables this way.
I searched on google but couldn't find a good result. Hope someone can help me out! Tx!
#!/bin/bash
QUEUE_01="a_b_c_qwer_e"
QUEUE_02="a_b_c_rewq_e"
QUEUE_03="a_b_c_tyui_e"
QUEUE_04="a_b_c_iuyt_e"
QUEUE_05="a_b_c_qazws_e"
QUEUE_06="a_b_c_swzaq_e"
ls -1 | while read file
do
cp $file $(echo $file | cut -f1 -d"_" ).$(echo $file | cut -f2 -d".")
done
Also known as xirixiz