所以我几天来一直在努力解决这个问题,尝试使用grep
,sed
和awk
的解决方案,所有解决方案都在某种程度上有效但不符合我的确切要求。以下是我正在使用的数据。我需要在每个新行--------
字符串之间提取二等奖,或者在列表中的每个域之间获得一等奖。
我需要为每个域提取特定的数据库详细信息。
somedomain.co.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin_1
Read only somepassword
Read/Write somepassword
Server name some.host.net
somedomain.org.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin
Read only somepassword
Read/Write somepassword
Server name some.host.net
somedomain.co.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin_1
Read only somepassword
Read/Write somepassword
Server name some.host.net
somedomain.co.za
\---------------------------
Server name some.host.net
Database name somedb_wp
Full somepassword
Login somelogin_4
Read/Write somepassword
Read only somepassword
Server name some.host.net
Read/Write somepassword
Read only somepassword
Login somelogin_3
Full somepassword
Database name somedb_db3
somedomain.co.za
\---------------------------
答案 0 :(得分:0)
我发现这个问题相当模糊,但我认为您可能正在寻找类似awk
脚本的内容:
/.*\.(co|org)\.za/ { print RECORD; RECORD = $0; next }
{ RECORD = RECORD "\n" $0 }
END { print RECORD }
当然,除了简单地打印记录之外,您可能还想做其他事情。
答案 1 :(得分:0)
您可以使用awk执行此操作,以使用域信息获取每个数据库属性的条目。 这是要求吗?
putSampleR :: Handler ()
putSampleR = do
Args{..} <- requireJsonBody
<balabalabala>
where
data Args = Args { a :: Int }
instance FromJSON Args where
假设awk 'NR==nr{
next
}
NF==1{
nr=NR+1;
dmn=$1;
i=1;
next
}
dmn"@"$1"@"i in a{
i++
}
{
a[dmn"@"$1"@"i];
b[dmn","i]=b[dmn","i]","$0
}
END {
for ( i in b) print i""b[i]
}' file
中没有空行。
I / P:
File
O / P:
v.co.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin_1
Read only somepassword
Read/Write somepassword
Server name some.host.net
w.org.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin
Read only somepassword
Read/Write somepassword
Server name some.host.net
z.co.za
\---------------------------
Database name somedb_db1
Full somepassword
Login somelogin_1
Read only somepassword
Read/Write somepassword
Server name some.host.net
y.co.za
\---------------------------
Server name some.host.net
Database name somedb_wp
Full somepassword
Login somelogin_4
Read/Write somepassword
Read only somepassword
Server name some.host.net
Read/Write somepassword
Read only somepassword
Login somelogin_3
Full somepassword
Database name somedb_db3
x.co.za
\---------------------------