About the difference between the apple command sed and CentOS use

Source: Internet
Author: User

About the difference between the Apple command line and the CentOS command line sed

Yesterday received the task of leadership, let me write a script, the purpose is to specify a certain number of self-increment, after receiving the task I think the task is too simple, but I was careless.

The main idea is to lose, so I suffer.

First I locked the target value, but the target value is not unique, I can only first lock to the target value of the ancestor target, the value of the ancestor target is the only file information. So OK, get to work.

After taking the value that is self-increment and replace, self-increment no problem, replace it with SED.

What I didn't think of was that there was a difference between the use of SED in Apple's command line and CentOS.

Centos:sed-i ' $bs #<string> $c </string>#<string> $NUM </string> #g ' $DIR $filemac:sed-i "' $b s# <string> $c </string>#<string> $NUM </string> #g ' $DIR $file

A couple more "", The Pit is dead, thank http://blog.csdn.net/dawn_moon/article/details/8547408

The thought of command line success, instant Meimei, but one put into the script, an instant explosion.

The reason is that the script runs, does not show the two parameters $b and S, after my repeated pairs of double quotation marks, single quotation marks, single quotation marks, double quotation marks, double quotation marks, single quotation marks and double quotes plus single quotation marks, no results.

Later, a space was added between $b and S, and the blood was resurrected.


Below is I write the garbage script, hope can help to novice.

Apple system command line #!/bin/bashdir=/users/admin/config/teacher/develop/file=info.plist.oriif [$USER =admin]; Then echo "This user is admin" CP $DIR $file $DIR $file.bak a= ' cat-n $DIR $file|grep "<key>cfbundleversion< ;/key> "|awk ' {print $} ' b=$ (($a + 1)) c= ' cat-n $DIR $file|grep $b |awk-f" [<>] ' {print $} ' num=$ (($c + 1) sed-i "" ' $b s#<string> $c </string>#<string> $NUM </string> #g ' $DIR $file else echo "PL Ease use admin "fi


This article is from "for the tribe!" "Blog, be sure to keep this provenance http://10309478.blog.51cto.com/10299478/1725703

About the difference between the apple command sed and CentOS use

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.