The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
grep - searching for a specific string manthasirisha Shell Programming and Scripting 2 01-05-2006 09:24 AM
searching text files on specific columns for duplicates Gerry405 UNIX for Dummies Questions & Answers 2 08-18-2005 10:51 AM
Searching for a specific phrase on Unix server mmcaleer UNIX for Dummies Questions & Answers 1 02-07-2005 04:18 PM
Can't figure out how to display specific data from a line using awk. ctcuser Shell Programming and Scripting 1 06-24-2004 02:55 PM
Searching for a specific string in an argumnet dinplant Shell Programming and Scripting 1 03-11-2002 03:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-02-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
Searching for data on a specific line numbers

Hi,
I have a file on windows and have some unix utilitties available on windows. This file is very large and have over 5 million record. I am not able to open this file in Window Editor. I am trying to see bad data on a specific lines. I just have line numbers that has bad data. I need to see the data at that line number.
I am trying to see data let say on line 411108. I tried tail -n 411108 filename but it shows last 411108 lines instead of data on line 411108. I have tried grep and head command but it returns thousands of rows. I installed VIM on windows and tried opening the file but it only clocks for hours and does not open file. I had to kill the job.

Is there a unix command that I can use to view specific data at a certain line number. I also have sed and gawk utility available on windows.

Will appreciate any help....

Thanks
Raj
  #2 (permalink)  
Old 06-02-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
sed -n '411108p' < datafile
will do it. However after printing the line, sed will continue to read until end of file. So this may be faster:
sed -n '411108p;411109q' < datafile
  #3 (permalink)  
Old 06-02-2005
rkumar28 rkumar28 is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 34
Thanks a lot for a quick reply.This worked.
Just curious to know the significance of "p" and "q" in the sed command below.
sed -n 411108p;411109q < datafile

If I remove the "p" and "q" the sed errors out.

Thanks
Raj
  #4 (permalink)  
Old 06-02-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
p=print
q=quit
  #5 (permalink)  
Old 06-16-2005
jhansrod jhansrod is offline
Registered User
  
 

Join Date: May 2005
Posts: 80
Problem with sed

Hi all

I have a file jh that contains :-
1
2
3
4


I use have a script as follows :-
#!/usr/bin/ksh
F1=jh
y=1
z=1

FS1=`cat $F1 | wc -l`

while [ $y -le $FS1 ]
do
set -xv
z=`expr $y + 1`
st=$y"p"
ed=$z"q"
V1=`sed -n \'$st\;$ed\' \< $F1`
echo $y
y=`expr $y + 1`
read a
done


When I execute this, I get the following result.
+ + expr 1 + 1
z=2
+ st=1p
+ ed=2q
+ + sed -n '1p;2q' < jh
sed: 0602-403 '1p;2q' is not a recognized function.
V1=
+ echo 1
1
+ + expr 1 + 1
y=2
+ read a


Can anyone tell me what is wrong ?

Thx

J
  #6 (permalink)  
Old 06-16-2005
muthukumar muthukumar is offline
Registered User
  
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
You can make as,

#!/usr/bin/ksh
F1=jh
y=1
z=1

FS1=`cat $F1 | wc -l`

while [ $y -le $FS1 ]
do
set -xv
z=`expr $y + 1`
st=$y"p"
ed=$z"q"
V1=`sed -n $st\;{$ed\;} < $F1`

echo $y
y=`expr $y + 1`
read a
done
  #7 (permalink)  
Old 06-17-2005
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0