![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| bash and ksh: variable lost in loop in bash? | estienne | Shell Programming and Scripting | 2 | 08-25-2008 03:09 PM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| question on sed grep awk from variable | 3Gmobile | Shell Programming and Scripting | 9 | 08-11-2006 01:15 AM |
| Simple grep - Not sure it makes sense! | GNMIKE | UNIX for Dummies Questions & Answers | 5 | 10-22-2005 03:51 AM |
| Linux Benchmarks Makes No Sense | philip_38 | Linux Benchmarks | 0 | 07-22-2005 11:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
BASH: How do I grep on a variable? (or simmilar question that makes sense)
Hi, I've been running code which very frequently calls books.csv. e.g: Code:
grep -i horror books.csv > temp Except, I'm trying to move away from using temporary files or frequently calling books.csv to improve efficiency. So I tried something like Code:
bookfile=$(cat books.csv) grep -i horror $bookfile Needless to say, it explodes (giving me about 40 lines of: "grep [data here] no such file or directory"), that's before I even try and save my grep output as a variable. Don't suppose anyone knows what path I need to be taking? Thanks in advance |
|
||||
|
Set your variable as follows:
bookfile=`cat books.csv` Then your grep should get every line that has the word "horror" in it. If you want specific fields from each line, you'll need to do something similar to: bookname=`echo $bookfile | awk -F"," '{print $1}'` This assumes the fields are separated by commas (true csv format) and that the first field is the bookname. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|