Searching for data on a specific line numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for data on a specific line numbers
# 8  
Old 06-17-2005
Quote:
Originally Posted by jhansrod
Can anyone tell me what is wrong ?
Yes, i can: the problem is your following line:

Code:
V1=`sed -n \'$st\;$ed\' \< $F1`

Presumably i would work with a generous dose "eval"-statements, because the problem is: the shell is aware of what a parameter to a command is and per definitionem an expanded variable is such a parameter. Therefore you don't need the single quotes one usually encloses his sed-statements in. Here is a basic alternative to your script which works as a pipeline filter:

Code:
#!/bin/ksh

typeset -i iBegin=$1
typeset -i iEnd=$1
typeset    chSedCmd=""

(( iEnd += 1 ))
chSedCmd="${iBegin}p;${iEnd}q"

sed -n $chSedCmd

exit 0

use with "cat <file> | <scriptname> <number>" where "<number>" is the number you want to display. My first take was:

Code:
chSedCmd="\'${iBegin}p;${iEnd}q\'"

and it produced the same error as your script: "function ... can not be parsed". The same happened with

Code:
chSedCmd="'${iBegin}p;${iEnd}q'"

When I removed the single quotes from the string it worked.

Hope this helps.

bakunin
# 9  
Old 06-18-2005
Bug try following

Instead of
V1=`sed -n \'$st\;$ed\' \< $F1`

Use following syntax :
V1=`sed -n "$st;$ed" $F1`

It should work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

2. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

3. Shell Programming and Scripting

Need help to replace a pattern on specific line in a data file

Hi, I want to replace specific pattern "-2.0000 2" by "1.0000 3" on a particular line (line #5) in a file 1.dat. I have about 50 more files similar to 1.dat in which I want to do this correction. Can you please suggest how can I make change only at this particular line of a file... (6 Replies)
Discussion started by: anuj06
6 Replies

4. UNIX for Dummies Questions & Answers

Get line numbers while searching the pattern in log

Hi Folks, I am searching for a pattern in logs through putty by opening the file in vi editor and reaching to the last of the file by $ and then searching the pattern , lets say I have to search the pattern abc then it would be ?abc Now I want line numbers along with the matching pattern to be... (3 Replies)
Discussion started by: SankalpS
3 Replies

5. Shell Programming and Scripting

Help with figuring division and addition based on column data and line numbers

I have a data file in the format of 1234 xxx 1234 xxx 1234 xxx 1234 xxxI want to be able to calculate the following - COLUMN1+((LINENUMBER-1)/365) The output needs to preserve the 2nd column - 1234 xxx 1234.00274 xxx 1234.00548 xxx What is the best way to do this? I am somewhat... (9 Replies)
Discussion started by: ncwxpanther
9 Replies

6. Shell Programming and Scripting

Extract character between specific line numbers

Hi guys, I have txt file and I would need to extract all the contents between specific line numbers. Line 1: apple Line 2: orange Line 3: mango Line 4: grapes Line 5: pine apple I need to extract the content between line 2 and 4, including the contents of Line 2 and 4 so the ouput... (2 Replies)
Discussion started by: gowrishankar05
2 Replies

7. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

8. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

9. Shell Programming and Scripting

Searching a specific line in a large file

Hey All Can any one please suggest the procedure to search a part of line in a very large file in which log entries are entered with very high speed. i have trued with grep and egrep grep 'text text text' <file-name> egrep 'text text text' <file-name> here 'text text text' is... (4 Replies)
Discussion started by: NIMISH AGARWAL
4 Replies

10. Shell Programming and Scripting

Can't figure out how to display specific data from a line using awk.

Hello, I cannot figure this one out. I would like to do the following. I have a line that has 7 words. It is possible that the line can have 20 words too. I always want to show the 9th word and beyond. The 9th word will always change so I do not have something to search for, so I think... (1 Reply)
Discussion started by: ctcuser
1 Replies
Login or Register to Ask a Question