如何解析/ *基于内容

时间:2015-04-24 17:19:17

标签: bash parsing scripting

我有一个包含以下内容的文件:

/*
  // iOS device address. Ensure 'appium' and 'ios_webkit_debug_proxy'
  // are running, and 'ignoreSynchronization' is true in utils
  seleniumAddress: 'http://localhost:4723/wd/hub',
  capabilities: {
    browserName: '',
    platformName: 'iOS',
    platformVersion: '7.1',
    deviceName: 'iPhone',
    autoWebview: true
  },
*/

/*    
  // android device address. Ensure 'appium' and 'ios_webkit_debug_proxy'
  seleniumAddress: 'http://localhost:4723/wd/hub',
  capabilities: {
    browserName: '',
    platformName: 'Android',
    platformVersion: '4.2.2',
    deviceName: 'Nexus',
    autoWebview: true
  },
*/

如何解析文件以仅删除iOS或Android的注释?目前我只知道如何通过运行来删除/ * * /:

sed 's/\/\*//'
sed 's/\*\///'

2 个答案:

答案 0 :(得分:0)

使用此

sed -r 's|^\s+\/\/||'

答案 1 :(得分:0)

如果块周围的var roleId = roleManager.FindByName(id); var roleUsers = new RoleUsers { Role = new Role(id), Users = _db.Users.Where(x => x.Roles.Select(y => roleId.Name).Contains(id)).ToList() }; /*始终位于一行的开头,则以下小awk程序应该可以正常工作:

*/
需要将

awk -v MATCH="// android" ' /^\*\// { if (acc ~ MATCH) print acc "\n" $0; acc = ""; next} acc { acc = acc "\n" $0; next } /^\/\*/ { acc = $0; next } { print} ' file.txt 设置为正则表达式,该正则表达式描述了您在块内寻找的内容。您可以更精确地调整与块的开头和结尾匹配的模式。