Command that prints content of line5, or similar?


 
Thread Tools Search this Thread
Operating Systems Linux Command that prints content of line5, or similar?
# 1  
Old 07-06-2007
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
# 2  
Old 07-06-2007
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".
# 3  
Old 07-06-2007
Shell_Life, you probably want to quit after the print. There would be no need to read the remainder of the file.
# 4  
Old 07-06-2007
You are right, Reborg -- the quit is an important optmization:
Code:
sed 'X{p;q;}' input_file

# 5  
Old 07-09-2007
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 10:19 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crunch character combination and discard similar content

Hi guys ! I generated the power set of the set S={a,b,c} using crunch: crunch 1 3 abc and get the 39 possible subsets: a b c aa ab ac ba bb bc ca cb cc … (2 Replies)
Discussion started by: beca123456
2 Replies

2. Red Hat

hostname command prints nothing a null value

Hi , On my box everything works fine. But whenever I run command It returns nothing as you see @(none) too. Its very strange issue I have never noticed on any other system yet. Any one have any idea about this. Thank you (2 Replies)
Discussion started by: pratapsingh
2 Replies

3. Shell Programming and Scripting

Help with merge two file based on similar column content

Input file 1: A1BG A1BG A1BG A1CF A1CF BCAS BCAS A2LD1 A2M A2M HAT . . Input file 2: A1BG All A1CF TEMP (5 Replies)
Discussion started by: perl_beginner
5 Replies

4. Linux

similar command of ptree in linux

Hello guys, Is there any command to check the all child processes of a process like `ptree`? ptree is not working in Linux.. Regards, Raghu (3 Replies)
Discussion started by: raghu.iv85
3 Replies

5. Shell Programming and Scripting

another command similar to expect

Hi , I just wondering if there is any command that works similar to the expect command. I'm trying to setup a korn shell script that goes to remote servers and executes a command likes : su - username -c "script to execute " but then it'll prompt for the password so if I can provide... (1 Reply)
Discussion started by: arizah
1 Replies

6. Shell Programming and Scripting

display content between all similar tags pattern

hi, I m stuck at a point for more than 3days. My doubt is pretty simple.. I have a web page content in $content. ( got this by using LWP).. Now I want to display the content matching a pattern. I tried if($content =~ m{<div class="abc">(.*?)</div>}s){ print $1;} that will... (4 Replies)
Discussion started by: therockravi
4 Replies

7. Shell Programming and Scripting

Command similar to watch

Hi all, I am trying to create a file that shows the CPU usage, constantly updating (similar to TOP). So far i have a file (called test) containing: echo "The current CPU usage is:" `ps -e -o pcpu|awk 'NR > 0 { s +=$1 }; END {print s"%"}'` and then I ran the command: watch -d 0.5 -t... (3 Replies)
Discussion started by: mikejreading
3 Replies

8. UNIX for Dummies Questions & Answers

Command similar to doskey

Hello all, I need a help in unix. is there any command in unix similar to doskey in MS Dos. It taked pain to enter the big command again and again.. the up and down arrows do not bring the previous commands on the prompt. so pls let me know if there is any command to enable the doskey kind of... (4 Replies)
Discussion started by: halel
4 Replies
Login or Register to Ask a Question