LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2011, 04:58 AM   #1
eRzBeNgEl
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-10-2011, 05:01 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
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
 
Old 04-10-2011, 05:01 AM   #3
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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
 
Old 04-10-2011, 05:49 AM   #4
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
Code:
for thing in G4_SBLW/G4_500k_ke_1E_03_17000U_Entrainment_StPr_StT/data/*
do csv2tec ${thing} ${thing%.*}.dat
done
 
Old 04-10-2011, 06:22 AM   #5
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Quote:
Originally Posted by Andrew Benton View Post
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
 
3 members found this post helpful.
Old 04-10-2011, 08:06 AM   #6
wpeckham
Senior Member
 
Registered: Apr 2010
Location: USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 1,660

Rep: Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584Reputation: 584
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.
 
Old 04-11-2011, 08:20 AM   #7
eRzBeNgEl
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 04-11-2011, 08:35 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
You could try something like
Code:
cd <dir>
for file in *.csv
do 
    fname=$(basename $file csv)
    csv2tec $file ${fname}dat
done
NB: Untested!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
Bash, trying to program an easy debug switch in my script helptonewbie Programming 13 12-31-2008 03:02 AM
Easy Bash Script Question skibud2 Linux - Newbie 1 11-17-2004 12:14 PM
Bash script!! need help!!!!!could be easy! yulitao Programming 3 03-25-2004 07:52 PM
Easy bash script question TheRealDeal Linux - General 11 08-26-2003 10:45 PM


All times are GMT -5. The time now is 02:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration