使用Notepad ++或在linux中从列表中的每一行复制特定字符(:* :)前面的输出

时间:2017-04-26 20:25:00

标签: linux notepad++

我有一个列表,我想复制每行中的每个单词:*在每一行创建一个新列表。

例如,

当前列表 -

 - ftp1:*:1737:199:User &:/home/ftp1:/bin/clish  
 - juan:*:1738:199:User &:/home/juan:/bin/clish 
 -  kevin:*:1739:199:User &:/home/kevin:/bin/clish   
 -  mailer:*:1740:199:User &:/home/mailer:/bin/clish

新列表或文件 -

 - ftp1  
 - juan  
 - kevin  
 - mailer

2 个答案:

答案 0 :(得分:1)

  • 控制 + ħ
  • 找到:public class SSLConfig { private static final String PROD_INSTANCE = "Prod"; private static final String STG_INSTANCE1 = "Staging"; private static final String STG_INSTANCE2 = "Stg"; private static final String QA_INSTANCE = "QA"; private static final String DEV_INSTANCE = "DEV"; private static HostnameVerifier getHostnameVerifierForInstance(String instance, String hostnameVerification) { LOGGER.info("HostnameVerifier For Instance = {}, hostnameVerification = {}",instance,hostnameVerification); HostnameVerifier hostnameVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; if(StringUtils.isNotBlank(instance)) { if ((instance.trim().toLowerCase().startsWith(PROD_INSTANCE.toLowerCase()) || instance.trim().toLowerCase().startsWith(STG_INSTANCE1.toLowerCase()) || instance.trim().toLowerCase().startsWith(STG_INSTANCE2.toLowerCase()) || instance.trim().toLowerCase().startsWith(QA_INSTANCE.toLowerCase()) || instance.trim().toLowerCase().startsWith(DEV_INSTANCE.toLowerCase())) && StringUtils.isNotBlank(hostnameVerification) && hostnameVerification.trim().toLowerCase().equalsIgnoreCase("true")) { hostnameVerifier = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { DefaultHostnameVerifier verifier = new DefaultHostnameVerifier(); return verifier.verify(hostname, session); } }; } } return hostnameVerifier; } }
  • 替换为:^([^:]+).*$
  • 全部替换

<强>解释

$1

<强>替换

^         : begining of line
  ([^:]+) : group 1, every thing that is not a colon
  .+      : 0 or more any character
$         : end of line

给定示例的结果:

$1        : group 1

答案 1 :(得分:1)

cat inputfile | sed 's/:.*//' > outputfile

我会从第一个冒号开始删除所有内容。我建议你寻找sed示例。有很多。