LinuxQuestions.org
Visit Jeremy's Blog.
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 09-17-2008, 09:39 AM   #1
feelamit
LQ Newbie
 
Registered: Sep 2008
Posts: 1

Rep: Reputation: 0
Unhappy "shell script :- urgently require help"


hello everyone,

i have to read a data from a flat file based on some line number, when the line number is known to me.
so i can write command such as :-

b=`sed -n -e 10p /util/xfer/trsfers/TL_MONTH1.csv`

but suppose if i want to use same command inside some loop like this

b=`sed -n -e $var /util/xfer/trsfers/TL_MONTH1.csv`
where var=row number.

this will not work why??
is it because "sed" reads data at one shot.??

can u please advise me how can i read the data inside a loop from different file based on row number.??

i badly require this .

thanks in advance

regards
 
Old 09-17-2008, 09:52 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
var=10
sed -n -e "$var"p /util/xfer/trsfers/TL_MONTH1.csv

should work.
 
Old 09-17-2008, 09:52 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Try quoting the variable. Also, you need the 'p' after it, unless it's included in the variable contents, that is. This worked for me:
Code:
b=`sed -n -e "$var"p /util/xfer/trsfers/TL_MONTH1.csv`
It didn't work without quotes for me either, but I honestly couldn't tell you why.
 
  


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
shell script with curl: HTML "post" giving me a headache Kropotkin Programming 4 05-06-2008 09:51 PM
converting shell script from "dialog" to "xdialog" kushalkoolwal Programming 1 02-25-2008 09:40 PM
Pass "yes" or "no" to the shell script say_hi_ravi Programming 3 02-14-2008 12:58 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 03:11 AM


All times are GMT -5. The time now is 02:19 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