Shell 格式错误的明文文件中的Grep键值对
我正在编写一个shell脚本,它需要从数据库中检索键值对 格式化的明文Shell 格式错误的明文文件中的Grep键值对,shell,awk,sed,grep,cygwin,Shell,Awk,Sed,Grep,Cygwin,我正在编写一个shell脚本,它需要从数据库中检索键值对 格式化的明文.txt文件。.txts是MS Word文档,具有 已保存为纯文本。从下面的示例中可以看出 Sample_Profile.txt,键后面的值由 开始括号和结束括号 User First Name (Goofball) User Last Name (Goofberg) Email Address (goofball@example.com) Password (sogoofedrightnow) 1. Profil
.txt
文件。.txt
s是MS Word文档,具有
已保存为纯文本。从下面的示例中可以看出
Sample_Profile.txt
,键后面的值由
开始括号和结束括号
User First Name
(Goofball)
User Last Name
(Goofberg) Email Address
(goofball@example.com)
Password (sogoofedrightnow)
1. Profile details
Profile name* (Goofball's Profile) Profile Id**
(Guid2763944-a234)
输出:
Goofball
输出:
Goofball
FIRST_NAME=$(grep "User First Name" Sample_Profile.txt | sed 's|[^(]*(\([^)]*\)).*|\1|')
#grep User First Name key and pipe to sed to get the value bewteen parentheses
sed -i -e 's/USER_FIRST_NAME/'"$FIRST_NAME"'/g' UserName.txt
echo $FIRST_NAME
# outputs "User First Name" when it should get "Goofball" (grep is not
# piping correctly due to white space)
awk '/User First Name/ {print $2}' RS=')' FS='('