Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Sort lines

Original Message
Name: zbynda
Date: May 14, 2005 at 08:03:11 Pacific
Subject: Sort lines
OS: XP
CPU/Ram: 1600/512
Comment:
I have input text file. The output file should have the lines in this way: first line from input file should be the last line in the output file, the second line in the input file should be the last but one line in the output file and so on. I can use sort function and one additional file. How to do this? thanks


Report Offensive Message For Removal

Response Number 1
Name: Joseph.Huber
Date: May 17, 2005 at 05:20:01 Pacific
Subject: Sort lines
Reply: (edit)
Well, to what purpose, and in which environment ?
If I understand it correctly, You want to store the file 'lines' in reversed order ?
And the system is VMS (otherwise post in a different forum :-).
The simplest, without intermediate files, is:
Read the file line-by-line, store lines in an array of strings, then write the output file looping over the array in reversed index order.
This way is only limited by the available memory in Your process.

Second way:
read the file line-by-line, write intermediate file with line numbers preceding the text; use SORT/key=(pos:1,size:n,descending)
Then read the sorted intermediate file again, remove the line numbers.

Without writing Your own program, use the a TPU editor procedure
( http://wwwvms.mppmu.mpg.de/vmssig/src/tpu/EVE_LINE_NUMBERS.TPU
).
This makes 2 editor commands: NUMBER and UNNUMBER.
So the sequence is:
$ EDIT/TPU/Command=EVE_LINE_NUMBERS.TPU
command NUMBER
command WRITE TEMP.TXT
command SPAWN SORT ... ! the above sort command
command READ output of sort command
command UNNUMBER
Now we have the text file in reversed line number.


You can of course do all entirely in DCL:
$ open/read in myfile
$ open/write out numbered_file
$n=1
$loop:
$read/end=done in line
$ write out f$fao("!6UL",n),line
$goto loop
$done:
$close in
$close out
$ sort numbered_file reversed_file /key=(pos:1,siz:6,descending)
$ open/read in reversed_file
$ open/write reversed_text
$loop2:
$ read/end=done2 in line
$ write out f$extract(7,f$length(line)-7,line)
$ goto loop2
$done2:
$ close in
$ close out



Report Offensive Follow Up For Removal

Response Number 2
Name: Joseph.Huber
Date: May 17, 2005 at 05:59:09 Pacific
Subject: Sort lines
Reply: (edit)
Correct in my previously posted DCL procedure:
insert $ n = N + 1
before goto loop.
and replace the 7 in f$extract(... by 6 two times.


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Sort lines

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC