- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Command Question..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 02:52 PM
09-27-2011 02:52 PM
Hi All,
I have a file which looks like this -
Allan M
Allan T
John H
Terry P
Harry P
I want to print the file as well as do a line count -
Allan M
Allan T
John H
Terry P
Harry P
5
Want to do this as fast as it can be done, for example if we are talking about 10 miliion lines.
Need to do this in one single command without ";".
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 03:11 PM
09-27-2011 03:11 PM
Re: Command Question..
Hi Allan:
# perl -ple '$n++;END{print $n}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 03:19 PM
09-27-2011 03:19 PM
Re: Command Question..
Tried but getting error -
Unrecognized character \xEF in column 19 at -e line 1
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 03:22 PM - edited 09-27-2011 03:50 PM
09-27-2011 03:22 PM - edited 09-27-2011 03:50 PM
SolutionHi (again) Allan:
@allanm77 wrote:
Tried but getting error -
Unrecognized character \xEF in column 19 at -e line 1
Well, re-type what I posted. However, here's an even shorter variation given your requirement:
perl -ple 'END{print $.}' file
...or if you prefer:
awk '{print};END{print NR}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2011 03:50 AM
09-28-2011 03:50 AM
Re: Command Question..
Of course I like the perl solution, but what is wrong with good old plain fast default unix tools?
$ wc -l<file>>file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2011 08:17 AM
09-28-2011 08:17 AM
Re: Command Question..
>but what is wrong with good old plain fast default unix tools?
Because there is no tool the both prints and gives that count.
(Unless you use nl(1) or cat(1) to number each line.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2011 08:46 AM
09-28-2011 08:46 AM
Re: Command Question..
Ah, I misread the OP as that it was required to add the line count to the end of the file.
Mea culpa.