LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Easy Bash Script Linux?! How?! (https://www.linuxquestions.org/questions/linux-newbie-8/easy-bash-script-linux-how-874081/)

eRzBeNgEl 04-10-2011 03:58 AM

Easy Bash Script Linux?! How?!
 
Hey
Can somebody help me? I need following bash script:

All *.csv files i.e. this folder G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/
should run by "csv2tec" and give out a *.dat result file in the same folder. For example

G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/Test1.csv
G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/Test2.csv

csv2tec Test1.csv Test1.dat
csv2tec Test2.csv Test2.dat

and so on. It is important for me that the filename of the *.csv ist the same as the *.dat file

Can anyone help me?

Thanks

EricTRA 04-10-2011 04:01 AM

Hello and Welcome to LinuxQuestions,

What have you got already and where is it failing? LQ is all about helping users with problems/questions that relate to Linux but you'll not find many here that offer you ready made solutions. You should put in the work for yourself and in doing so you'll learn a lot more.

Look into find, ls, grep and redirecting output to other commands.

Kind regards,

Eric

Snark1994 04-10-2011 04:01 AM

Look at the 'find' command, and in particular its 'exec' option :)

EDIT: Oooor the ones EricTRA said :P you'd probably be able to do it in a way you understand more easily using his commands

Andrew Benton 04-10-2011 04:49 AM

Code:

for thing in G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/*
do csv2tec ${thing} ${thing%.*}.dat
done


EricTRA 04-10-2011 05:22 AM

Quote:

Originally Posted by Andrew Benton (Post 4319792)
Code:

for thing in G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/*
do csv2tec ${thing} ${thing%.*}.dat
done


Hi,

And how are you helping the OP by handing him a solution he might not even understand? Have you considered for a minute that this might be homework? In my opinion it's a lot better to point a new user to the tools to use as I did. Not very helpful in my book.

Kind regards,

Eric

wpeckham 04-10-2011 07:06 AM

man pages
 
Sounds like homework to me as well.

IF you can already get and work through a list of the files, check the man page for 'basename'.

I am looking forward to seeing what you have so far, and finding out in what way it does not (yet)work.

eRzBeNgEl 04-11-2011 07:20 AM

Hey guys

Thanks for your help. I can say it is no homework, i just had a lot to do at work these days so there was no time to think about scripting...After finishing my project I am having more time to learn bashscripting on myself!

Thanks anyway

chrism01 04-11-2011 07:35 PM

You could try something like
Code:

cd <dir>
for file in *.csv
do
    fname=$(basename $file csv)
    csv2tec $file ${fname}dat
done

NB: Untested!


All times are GMT -5. The time now is 10:35 PM.