The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command similar to "touch" for modify File size sriharshareddyk UNIX for Advanced & Expert Users 3 11-14-2007 09:43 PM
Deleting all content in a file from command line kingdbag UNIX for Dummies Questions & Answers 2 07-20-2006 04:00 PM
Command similar to doskey halel UNIX for Dummies Questions & Answers 4 05-16-2006 04:49 AM
is there a content type command? aqh2 UNIX for Dummies Questions & Answers 3 11-19-2005 06:14 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-06-2007
Registered User
 

Join Date: Jun 2007
Posts: 8
Stumble this Post!
Command that prints content of line5, or similar?

Hello all;

I've been having trouble completing a script (bash) because I can't get past the issue of finding a line in a file. For example, I have a file like this:

ddmmmyyyy Lon Lat
24may2003 -100.0 24.1
25may2003 -100.1 24.0
28may2003 -99.5 23.2
....etc
05jun2003 -97.0 22.7
EOF

I'm making a loop, and I need a way to call a line number without specifying what the line contains (i.e., grep doesn't work). Here's what I had in mind:

n=2
While (something that makes the loop infinite); do
day=`command line${n} word1


if
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-06-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
One way to display a specific line number in a file:
Code:
sed -n 'Xp' input_file
Where "X" is a line number in the "input_file".
Reply With Quote
  #3 (permalink)  
Old 07-06-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,513
Stumble this Post!
Shell_Life, you probably want to quit after the print. There would be no need to read the remainder of the file.
Reply With Quote
  #4 (permalink)  
Old 07-06-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
You are right, Reborg -- the quit is an important optmization:
Code:
sed 'X{p;q;}' input_file
Reply With Quote
  #5 (permalink)  
Old 07-09-2007
Registered User
 

Join Date: Jun 2007
Posts: 8
Stumble this Post!
Thanks guys, the sed -n command is helpful.

Someone posted another reply, but it got deleted because I double-posted (notice the post is cut-off after "if." I can't remember what happened but I guess I ended up starting over and posted twice accidentally).

Here's jim mcnamara's reply to the deleted post, which got sent to my email:

Code:
awk ' {
     print "set time ", $1
     print "draw mark ", $2, $3
     } ' filename > file_for_a_graphing_program
output:

Code:
---------
set time 24may2003
draw mark -100.0 24.1
set time 25may2003
draw mark -100.1 24.0
set time 28may2003
draw mark -99.5 23.2
set time 05jun2003
draw mark -97.0 22.7
---------
source file = "filename" above:

Code:
---------
24may2003 -100.0 24.1
25may2003 -100.1 24.0
28may2003 -99.5 23.2
05jun2003 -97.0 22.7
---------

Last edited by vgersh99; 07-09-2007 at 06:19 AM. Reason: code tags
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0