Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 15

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.

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

Rep: Reputation: 15
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, 10:24 AM   #3
Registered: Jan 2001
Location: work
Distribution: Redhat, Mandrake
Posts: 33

Original Poster
Rep: Reputation: 15

Thanks that worked perfectly. Thanks for the help.



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 02:43 PM
[c shell] file empty? saiz66 Programming 1 09-28-2004 10:57 PM
downloading a file from shell - how? Mytherall Linux - Newbie 1 02-27-2004 09:31 PM
File Maintenance in a shell script? mdscudder Linux - General 1 02-20-2003 05:14 PM
shell file with tomcat Mikoreli Linux - General 3 07-16-2001 02:13 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

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