The UNIX and Linux Forums  

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
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 09:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-21-2007 01:29 AM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 05:34 PM
identifying duplicates line & reporting their line number stresslog UNIX for Dummies Questions & Answers 5 04-24-2006 01:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-16-2006
misenkiser misenkiser is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 36
Get line number

Hi,

How do i get line number of a variable which contains entire line
and then capture all lines till EOF ?

For eg .

Variable vr will contain the string "this is a string"

I need to get line number of this line in the file and then starting from this number till EOF
I want to capture all lines in between
  #2 (permalink)  
Old 11-16-2006
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
you can get line using following command

grep -n $vr filename | cut -d: -f1

note:- vr = "this is a string"
  #3 (permalink)  
Old 11-16-2006
misenkiser misenkiser is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 36
Now how do i capture all lines till EOF?
  #4 (permalink)  
Old 11-16-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
If all you need is the lines from whatever $vr holds till EOF, then


Code:
sed -n "/$vr/,/G/p" yourfile.txt > out.txt

  #5 (permalink)  
Old 11-16-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
Quote:
Originally Posted by vino
If all you need is the lines from whatever $vr holds till EOF, then


Code:
sed -n "/$vr/,/G/p" yourfile.txt > out.txt
Why /G/ ?

Code:
sed -n "/$vr/,\$p" yourfile.txt > out.txt


Jean-Pierre.
  #6 (permalink)  
Old 11-16-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by aigles
Why /G/ ?

Code:
sed -n "/$vr/,\$p" yourfile.txt > out.txt


Jean-Pierre.
Darn... I had sed -n "/$vr/,$p" yourfile.txt > out.txt with me and it didnt work. I forgot about escaping it.. aarg.. long day !!
Thanks !
  #7 (permalink)  
Old 11-16-2006
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
#! /usr/bin/ksh

while read line
do
basestr="this is a string"
if [[ $line != $basestr ]]
then
continue
fi
echo "abc" # start processing file from here
done < abc
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 06:21 AM.


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