Vi replacement command usage exercise

Source: Internet
Author: User
Vi replacement command usage exercise environment www.2cto. comRedHatLinux9 + VWWare8.0 + SSH3.2.9 assume that there is a CSV (commaseparatedvalue) file, which contains some information we need, but the format is incorrect. the column sequence of the data is as follows :...
Vi replacement command usage exercise environment www.2cto.com RedHat Linux 9 + VWWare 8.0 + SSH 3.2.9 question suppose there is a CSV (comma separated value) file, which contains some information we need, however, the format is incorrect. Currently, the column sequence of data is: name, company name, abbreviated state name, and zip code. now we want to regroup the data, for use in one of our software, www.2cto.com needs to be in the format of: name, abbreviated state name-zip code, company name. That is to say, we need to adjust the column order and combine two columns to form a new column. In addition, our software cannot accept any spaces (including spaces and tabs) before and after the comma. Therefore, we must remove all spaces before and after the comma. The original file is like this: Bill Jones ,??? HI-TEK Corporation ,? CA, 95011 Sharon Lee Smith ,? Design Works inconfigurated ,? CAS, 95012 B. Amos? ?,? Hill Street Cafe ,? CAS, 95013 Alexander Weatherworth ,? The Crafts Store ,? CA, 95014 we want to make it look like this: Bill Jones, CA 95011, HI-TEK Corporation Sharon Lee Smith, CA 95012, Design Works inreceivated B. amos, CA 95013, Hill Street Cafe Alexander Weatherworth, CA 95014, The Crafts Store solution Step 1: save The source file as a source file, for example, test.txt Step 2: Upload test.txt to Linux. here you can use The SSH File upload function. Step 3: open test.txt with vi Step 4: execute the following command (enter a colon when entering the command, exit and save and enter wq, and exit without saving and use q or q !): 1. remove all question marks (?) [Plain] % s /? // G 2 remove all spaces before and after the comma [plain] % s/[\ t] *, [\ t] */, /g 3 implementation function [plain] % s/\ ([^.] * \), \ ([^.] * \), \ ([^.] * \), \ ([^.] * \)/\ 1, \ 3 \ 4, \ 2/g implementation effect
 
Related Article

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.