LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-22-2001, 03:19 PM   #1
Mike_the_Man
Member
 
Registered: Jan 2001
Location: work
Distribution: Redhat, Mandrake
Posts: 33

Rep: Reputation: 15
Question


This may seem trivial, but I am trying to figure out how I can display a certain line in a file. I have been doing:

set myLine = 2

cat -n MyFile |grep $myLine[^0-9] | awk -F " " '{print $2}'

the cat -n numbers the lines in the file
the grep looks for a line that is specified in myLine
the awk just prints out the second column

But, it doesnt work I am doing this in a C-shell script. If I take out the variable and put in the number 2, it will work. It does not like the variable. Any help would be greatly appreciated. Thanks.


Mike
 
Old 01-23-2001, 09:51 AM   #2
chay
LQ Newbie
 
Registered: Jan 2001
Location: Santiago, Chile
Posts: 21

Rep: Reputation: 15
#!/bin/bash
cat -n $1|grep -E ^' '+$2|cut -f2
# where $1 is the "file name" and $2 the line number
# cat -n format the output like this " 2\tthe line here"
# grep -E (ext. regexp.) will find space from the begining
# and then a number (your desired number line)
# cut -f2 will get the "field" number 2 (the line here)
# Hope this help
 
Old 01-23-2001, 11:24 AM   #3
Mike_the_Man
Member
 
Registered: Jan 2001
Location: work
Distribution: Redhat, Mandrake
Posts: 33

Original Poster
Rep: Reputation: 15
Smile

Thanks that worked perfectly. Thanks for the help.



Mike
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
file renaming with shell script or ? XJNick Linux - General 5 07-29-2005 03:43 PM
[c shell] file empty? saiz66 Programming 1 09-28-2004 11:57 PM
downloading a file from shell - how? Mytherall Linux - Newbie 1 02-27-2004 10:31 PM
File Maintenance in a shell script? mdscudder Linux - General 1 02-20-2003 06:14 PM
shell file with tomcat Mikoreli Linux - General 3 07-16-2001 03:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration