|
Re: can sed take take several line to produce multiple output: msg#00029editors.sed.user
> Can sed take the following input: > > header,login - telnet ssh, Thu Dec 08 11:08:55 2005, > subject,abc,def,123,456, abc.linux.com.my > > > and produce: > > Thu Dec 08 11:08:55 2005, Name=abd 2name=def phone=123 > phone2=245 >>From : abc.linux.com.my Access=telnet ssh If I understand correctly, the following sed script should do the trick: sed 'N;s/.*- \([^,]*\), \(.*\)\n[^,]*,\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\), \(.*\)/\2, Name=\3 2name=\4 phone=\5 phone2=\6\n>From : \7 Access=\1/' to reformat the file. If you only want records for a given Name=, you can do sed 'N;s/.*- \([^,]*\), \(.*\)\n[^,]*,\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\), \(.*\)/\2, Name=\3 2name=\4 phone=\5 phone2=\6\n>From : \7 Access=\1/;/Name=abc/!d' Those are both one-liners, in case either of our mailers bung it. It basically just joins the two adjacent lines into a single buffer for manipulation, picks out the fields of interest, reformats them in your desired format, and then, if they don't match the name you want to filter on. The second version then check to see if it contains "Name=abc"...if it doesn't, then it deletes the whole thing and moves on to the next 2-line pair. It's been a while since I've used more than about 4 of those backreferences...seven was quite a hairball :) -tim ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/dkFolB/TM --------------------------------------------------------------------~-> -- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/sed-users/ <*> To unsubscribe from this group, send an email to: sed-users-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: can sed take take several line to produce multiple output: 00029, Angus Leeming |
|---|---|
| Next by Date: | Text Substitution and Script: 00029, Venky Chakravarthy |
| Previous by Thread: | Re: can sed take take several line to produce multiple outputi: 00029, Angus Leeming |
| Next by Thread: | Re: can sed take take several line to produce multiple output: 00029, shamrul ismawi |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |