Code used for batch query of text lines with the maximum number of characters

Source: Internet
Author: User

The a.txt file is as follows:
Aaaaaaa AAAA bbbbbb ccccccccccc dddd
AA aaaaaaa bbbbbbbbbb cccccccccc ddddddddddddd Eeeeeee
Aaaaaaaaaaaa bbbbbbbbbbbbb cccccccccccccccccccc
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbb
Aaaaaaaaa ccccccccc bbbbbbbbbbbbbbb ddddddddddddddddddd

Find the rows with the largest number of characters (excluding spaces) in the text in batch and output them. It is obvious that the contents are copied to the clipboard.Code:
Aaaaaaaaa ccccccccc bbbbbbbbbbbbbbb ddddddddddddddddddd

Requirements:
1. Do not generate temporary files
2. The code is concise, efficient, and versatile.
3. the bonus points are still based on ideas.

Shimo:Copy codeThe Code is as follows: @ echo off
Setlocal enabledelayedexpansion
Set n = 0
For/F "delims =" % I in (a.txt) Do (
Set "Ke = % I"
Set ke1 =! KE: =!
Set M = 0
Call: 1
)
Echo % Wang %
Pause
Goto: EOF
: 1
If not "! Ke1 :~ % M %, 1! "=" "Set/a m + = 1 & GOTO 1
If % m % gtr % N % set n = % m % & set Wang = % ke %
Goto: EOF

BATMAN:Copy codeThe Code is as follows: @ echo off
Set num = 0
For/F "delims =" % I in (a.txt) do set "str = % I" & call, set "str = % STR :=% %" & call: LP "% I"
Call, Echo % _ % num % characters
Pause> NUL & Goto: EOF
: Lp
Set "str = % STR :~ 1% "& set/a n + = 1
If defined STR goto lp
If % N % geq % num % set "num = % N %" & set "_ % num % = % ~ 1"
Set "n = 0"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.