Randall wrote regarding 'Re: [SLE] Assistance w/ getting text out of a file' on Mon, Jan 24 at 15:37:
Ryan,
On Monday 24 January 2005 13:25, Ryan McCain wrote:
I have a file that has 100 or so lines in this format:
dn: cn=SERVERNAME1,ou=NWSERVERS,ou=SERVER03,ou=iServices,ou=MON,o=LA dn: cn=SERVERNAME2,ou=NWSERVERS,ou=SERVER03,ou=iServices,ou=MON,o=LA dn: cn=SERVERNAME3,ou=NWSERVERS,ou=SERVER03,ou=iServices,ou=MON,o=LA
How can I strip out everything execpt the servername? Using either shell scripting, sed or perl?
Which field is "the" server name?
Assuming it's the "cn=" and that the log file name is "logFile", do this:
sed -e 's/.*cn=[^,][^,]*,.*//' logFile
Adjust it as necessary if you want a different field.
Are you sure that won't need adjusted regardless of the desired field? :) That'll just erase the whole line, unless your sed is different from mine. You may have meant sed -e 's/.*cn=\([^,][^,]*\),.*/\1/' logfile Or, even better, sed -ne 's/^.*cn=\([^,][^,]*\),.*$/\1/p' logfile I'd also include the line beginning and ending anchors, to explicitly match the whole line (I don't like being ambiguous), and use the -n option so it'll only print matching lines (when paired with the /p after the regex). --Danny, who would've used perl...