Copy the number of the next line to the back of the previous line, with a space separate batch _dos/bat

Source: Internet
Author: User

I would like to put a text on its contents for such a form:
25
69
89
99
120

Processed into the following forms:
25 69
69 89
89 99
99 120

This means that the next line of numbers is copied to the back of the previous line and separated by a space. Do not know DOS can do?

Copy Code code as follows:

@echo off
:: Copy the next line of numbers to the back of the previous line, separated by a space
Setlocal enabledelayedexpansion
for/f%%i in (test.txt) do (
set/a count+=1
Set first=!second!
Set second=%%i
If!count! GTR 1 echo!first!!second!
)
Pause

The general idea is to extract the number of each row, give the variable second, and at the same time, use the variable first to receive the variable second the previous value, so that second takes the number of the current row, and first gets the contents of the previous line. If you use if to determine whether the value of Count is 1, because when Count is 1, the value is not yet taken.

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.