LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-06-2012, 06:24 AM   #1
Love@Nagpur
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Unhappy How to get the line no. which have the max words...?


Please help me to get the solution for the scenario:
e.g. File :a.txt
One
One Two
One Two Three

1. How to get the line no. which have the max words in it ..?
The command should print(for above a.txt) : 3

2. How I can print the particular line in a file..?
E.g. If suppose I want to print the 3rd line

3. How to print the line no and word and character count for the every line present in the file?
e.g.
Line No. 1 Word : 1 Char Count: 3

Please help me ...
Also suggest me the best tutorial for the similar shell programs and commands..
Thanks in advance
 
Old 08-06-2012, 09:14 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,950
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
You can use the wc command to get number of lines, number of words and number of characters. (Type "man wc" for more details.)

You can use the grep command to get lines with specific information and also print the line number for the lines it finds. (Type "man grep" for more details.)

You can use awk to do a lot of this as well. Use of awk can become fairly sophisticated. Searching for specific usage cases in web searchers for what you want to do would be good even after you've gone through an awk tutorial. For most Linux subjects if you type the subject and tutorial in a web search you'll find many hits. (e.g. "awk tutorial"). Of course awk also has a man page (man awk).

Linux also has info pages that sometimes give more detail than the man pages.
 
  


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
regex problem to find min,max length words in file gvanto Linux - Newbie 4 01-30-2011 05:34 PM
[SOLVED] how can vim replace all the same words in a certain line. e3399 Linux - Newbie 3 12-02-2010 11:39 AM
break line into words nushki Programming 16 12-04-2009 09:15 AM
BASH: First words in a line JordanH Programming 7 10-24-2004 10:00 AM


All times are GMT -5. The time now is 10:34 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration