Linux under VI Replacement command usage exercises

Source: Internet
Author: User
Tags exit file upload zip ssh linux

Environment

RedHat Linux 9 + vwware 8.0 + SSH 3.2.9

Problem

Suppose there is a CSV (comma separated value) file with some of the information we need, but the format is problematic, and the current data is in the following order:

Name, company name, state abbreviation, ZIP code, now we want to talk about the data and rearrange it for use in one of our software,

The format required is: name, state abbreviation-zip code, company name.

That is, we're going to resize the column order and combine two columns to form a new column. In addition, our software cannot accept commas before any spaces (including spaces and tabs) are

We also have to remove all the spaces before and after the comma.

The original file is like this:

Bill Jones,??? Hi-tek Corporation, huh? CA, 95011

Sharon Lee Smith, huh? Design works Incorporated,? CA, 95012

B. Amos??,? Hill Street Cafe, huh? CA, 95013

Alexander Weatherworth, huh? The crafts Store, huh? CA, 95014

We want to make it look like this:

Bill Jones,ca 95011,hi-tek Corporation

Sharon Lee SMITH,CA 95012,design Works Incorporated

B. Amos,ca 95013,hill Street Cafe

Alexander weatherworth,ca 95014,the Crafts Store

Solve

Step One: Save the source file as a text document, such as Test.txt

Step two: Upload the test.txt to Linux, where you can use the SSH file upload function.

Step three: Will test.txt with VI open www.bianceng.cn

Step four: Execute the following command (note Enter a colon when entering a command, exit save input Wq, exit without saving using Q or q!):

1 Remove all the question marks (?) )

%s/?//g

2 Remove all spaces before and after commas

%s/[\t]*,[\t]*/,/g

3 Implementation Features

%s/\ ([^.] *\),\([^.] *\),\([^.] *\),\([^.] *\)/\1,\3 \4,\2/g

Implementation effect

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.