LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2008, 05:14 AM   #1
ch4920
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Rep: Reputation: 0
help w/ homework


newbie here. i am writing a bash script and when i use wc -l filename to get a line count it returns the line count and the file name. i would like to get the line count only(not the filename) and store it in a variable. also i need to get the process id of the script and store that in a variable too. any help is greatly appreciated. thank you

sorry wrong forum. trying to figure out how to delete

Last edited by ch4920; 04-29-2008 at 05:18 AM.
 
Old 04-29-2008, 05:28 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by ch4920 View Post
newbie here. i am writing a bash script and when i use wc -l filename to get a line count it returns the line count and the file name. i would like to get the line count only(not the filename) and store it in a variable.
We don't do homework here, but I'll give you a tip.
There's pipe or redirect as the first set of options,
and e.g. tools like cut or awk as a more brute-force
approach to the problem (removing the excess output).

Quote:
Originally Posted by ch4920 View Post
also i need to get the process id of the script and store that in a variable too. any help is greatly appreciated. thank you

sorry wrong forum. trying to figure out how to delete
Forum is fine ;}

Try
man bash
/\$\$



Cheers,
Tink
 
Old 04-29-2008, 05:28 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Welcome to LQ---and thanks for acknowledging homework. You'll get some flak regardless, but your approach has the best chance of getting help.

After the wc command, you can use "cut" to select a specific field. "man cut" for details.

For process ID, try this:
ps -e|grep scriptname

Then use cut to get just the process ID

To put command outputs into variables, there are two forms:
var=`command` (those are backtics, not single quotes)
var=$(command)

to augment whatever text you are using, go to http://tldp.org and get "Bash Guide for Beginners"

Last edited by pixellany; 04-29-2008 at 06:32 AM. Reason: typo--text not test
 
Old 04-29-2008, 05:38 AM   #4
ch4920
LQ Newbie
 
Registered: Apr 2008
Posts: 3

Original Poster
Rep: Reputation: 0
thank you very much
 
Old 04-29-2008, 07:22 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by pixellany View Post
For process ID, try this:
ps -e|grep scriptname
There also is a special variable for this. Simpler, cleaner and faster.
 
Old 04-29-2008, 08:01 AM   #6
fancylad
Member
 
Registered: Mar 2008
Distribution: slackware
Posts: 175

Rep: Reputation: 19
Quote:
also i need to get the process id of the script and store that in a variable too. any help is greatly appreciated.
There's also pgrep

Quote:
matt@matt-laptop:~$ sleep 1000 &
[1] 8272
matt@matt-laptop:~$ pgrep sleep
8272
 
  


Reply



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
Homework pixellany LQ Suggestions & Feedback 14 06-30-2006 07:20 AM
homework help louce Linux - Newbie 3 09-04-2005 08:00 PM
please help my homework again donotexpert Programming 7 08-23-2005 10:26 AM
help me(my homework) please! donotexpert Programming 4 08-20-2005 06:26 AM
Need homework help! bumstickie Linux - Newbie 3 10-28-2002 04:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:18 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
Open Source Consulting | Domain Registration