The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep question. saurabhsinha23 UNIX for Dummies Questions & Answers 3 12-11-2007 01:58 AM
Question about GREP Adriel UNIX for Dummies Questions & Answers 16 03-22-2007 08:03 AM
Another grep question kingdbag UNIX for Dummies Questions & Answers 6 10-27-2006 02:56 AM
grep & sed question der Kopf Shell Programming and Scripting 1 11-22-2004 04:49 AM
Grep question eloquent99 UNIX for Dummies Questions & Answers 4 02-20-2003 10:49 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 06-21-2007
72bronco 72bronco is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 2
grep question

Hello all,

I'm trying to grep a file for a particular line and character position number and place the contents into a variable that I will examine later.

The file should have the data I want in the 20th line and the 18th position on that line thru the 26th position on that line.

I've used grep in scripting before, but only to verify the existance of a certain string in a certain file...never to find a changing string and read it into a variable.

I've spent the last few hours googling this, but I'm afraid I'm too new to make sense of the results.

Can anyone help?

Thanks so much.
  #2 (permalink)  
Old 06-21-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
sed -n '20p' input_file | cut -c18-26
  #3 (permalink)  
Old 06-21-2007
72bronco 72bronco is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 2
Ahhh, sed. Shows how much of a newb I am. wrong tool for the job.

Thank you!
  #4 (permalink)  
Old 06-22-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
var=$(sed -n '20{s/^.\{17\}//;s/\(.\{9\}\).*/\1/p;q;}' file)
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 10:15 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