Computing.Net > Forums > Programming > Sorting text.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sorting text.

Reply to Message Icon

Name: Huzefa
Date: January 26, 2009 at 20:39:08 Pacific
OS: Windows XP
CPU/Ram: P4 / 2GB
Product: Intel / Family 15 model 6 stepping 5
Subcategory: Batch
Comment:

Is it possible to sort text within files where it parses two lines at once.

Input:
def
456
abc
123
ghi
789

Normal Output:
123
456
789
abc
def
ghi

Needed Output:
abc
123
def
456
ghi
789

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: January 26, 2009 at 21:42:26 Pacific
Reply:

If there wont be a zero, you can do this.
pseudo code:

For every line in the file (
Set /a expr=line-from-file
if expr == 0 (output the line to numbers.file)
else (output the line to text.file)
)
find out line counts of both files, example -
for /f "delims=: tokens=2" %%a in ('find /c /v "" numbers.file') do set numbercount=%%a
Similarly find lines of the text file.

Now, for /l %I in (1,1,smaller of the line count) do (
for /f "skip=%I" .... and read Ith line from both the file and output to target file. Go out of this for loop after processing Ith line.
)

--
Holla.


0

Response Number 2
Name: Huzefa
Date: January 27, 2009 at 00:07:39 Pacific
Reply:

Fortunately it does have a same string in the beginning.
type 2.txt | findstr /i /n "Name:" >> 2a1.txt
type 2.txt | findstr /i /n "Age:" >> 2b.txt
type 2a1.txt | sort /+17 >> 2a.txt
for /f "tokens=1-2 delims=]" %%a in ('type 2a.txt') do (echo %%a]%%b >> file.txt) && (type 2b.txt | findstr /i "\%%a]" >>file.txt)


"Line Count" was the magical word.
Thanks a Lot.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Make an exe with a batch ... SQLCMD database exists



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Sorting text.

Perl and Sorting Text www.computing.net/answers/programming/perl-and-sorting-text/17346.html

List traverse, batch (NT) www.computing.net/answers/programming/list-traverse-batch-nt/12910.html

Perl script www.computing.net/answers/programming/perl-script/13108.html