LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-14-2008, 06:07 AM   #1
Jeozp
Member
 
Registered: Dec 2004
Distribution: Debian
Posts: 40

Rep: Reputation: 15
using a whole lins as value in bash script


I have cvs document created in excel (don't ask ) and now I need to break it down into lines to use in a script?

The problem is that if I use something like this:

# for i in `cat foo.cvs` ; do echo $i ; done

$i ends up being broken up by spaces in the line. I can not remove the spaces. how can I make $i the whole line?

thx in advance
 
Old 03-14-2008, 09:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
You want a "while" instead of a "for" loop: 'cat file | while read something; do echo "{$something}"; done'.
 
Old 03-14-2008, 11:30 AM   #3
Jeozp
Member
 
Registered: Dec 2004
Distribution: Debian
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks for the lightning fast reply
Solved all my problems and a couple of more...

here is the final thing
 
Old 03-14-2008, 01:59 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590Reputation: 3590
Quote:
Originally Posted by Jeozp View Post
Solved all my problems and a couple of more...
Are you sure. You got:
Code:
#!/bin/bash

FILE=input_file.cvs
SUBJECT="Foo is sorted into baar"
RECEPIENT="he.who@wants.it"

cat $FILE | while read LIST; do echo $LIST | mail -s $SUBJECT $RECEPIENT ; done
...which means now $RECEPIENT receives `wc -l input_file.cvs` e-mails. You could have done 'cat $FILE | mail -s $SUBJECT $RECEPIENT' instead.
 
Old 03-14-2008, 02:38 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
Btw, there are very few occurrences where you actually need to use cat with one argument and a pipe. If you want to avoid the overhead of an extra process, and at the same time make what you’re doing clearer, you can let the shell handle the redirection for you:
Code:
while read LIST; do echo $LIST | mail -s $SUBJECT $RECEPIENT ; done < $FILE
Or
Code:
mail -s $SUBJECT $RECEPIENT < $FILE
 
Old 03-18-2008, 09:25 AM   #6
Jeozp
Member
 
Registered: Dec 2004
Distribution: Debian
Posts: 40

Original Poster
Rep: Reputation: 15
@unSpawn
Acutely thats is exactly what I want, the .cvs file is a list of tasks which get sent to our ticketing system and then get treated as separate task...

@osor
Thanks for the tip, will remember that one for the future.

here is the whole thing again
 
  


Reply

Tags
bash, script


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
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 05:11 AM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 12:33 PM
Bash script to create bash script jag7720 Programming 10 09-10-2007 08:01 PM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 07:51 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:19 PM.

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