Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-06-2012, 07:24 AM   #1
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 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?
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, 10:14 AM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,064
Blog Entries: 14

Rep: Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248Reputation: 1248
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.


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 06:34 PM
[SOLVED] how can vim replace all the same words in a certain line. e3399 Linux - Newbie 3 12-02-2010 12:39 PM
break line into words nushki Programming 16 12-04-2009 10:15 AM
BASH: First words in a line JordanH Programming 7 10-24-2004 11:00 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:05 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