| |
| |
| |
|
Comments:
<0> hi, is there a way to replace text on specified line? <1> apastinen: <line number> s/some/thing/ <2> small question: i have a file in which there are blocks of the type BEGIN:VCARD..END:VCARD. in those blocks, there can be the string BDAY:... if so i want to extract the line which starts with BDAY and the line which starts with FN: (in that specific block).. is that possible? <1> _ke: try: sed -n '/BEGIN:VCARD/, /END:VCARD/{ /^BDAY/ p; /^FN:/ p; }' <2> redduck676, works quite good.. <2> but it prints also the FN: with no BDAY string in it <1> _ke: that is what you asked for. <1> ''i want to extract the line which starts with BDAY and the line which starts with FN:'' <1> _ke: try: sed -n '/BEGIN:VCARD/, /END:VCARD/ p' <-- if you want entire block
<2> redduck676, read carefully ;) "if so..." <2> redduck676, this is not the same problem as in #bash ;) <1> _ke: try: sed -n '/BEGIN:VCARD/, /END:VCARD/{ /BDAY/ { /^BDAY/p; /^FN/ p; } }' <2> redduck676, thats good ;) now the name is missing only <2> redduck676, hmm is there a way to exclude those without ^BDAY ? <1> _ke: hmmmm? you don't want to print lines that begin with ^FN? <2> i have added a grep -B 1 BDAY , now it works <2> ;) <2> thans <2> thanks <1> _ke: N; /BDAY/ p <-- something like this can achive the same effect as that grep <1> adding D; at the end of that might be good idea :) <1> and yes, i am bored, how did you guess it? :) <2> ;) <2> let me try <2> where should i put the "D"? <1> maybe after the 'p' <2> doesnt work really ;) how can i remove the newline? \n or .$ dont work here.. <1> _ke: depends. which newline? if the one between line before BDAY and line with BDAY try s/\n// (if dones't work you'll need to p*** sed literal new line) <2> how can i p*** a literal new line? :) <1> _ke: in bash: sed -e 'some commands <1> more commands' <2> i just have done that :) <2> sed -e 's/\n//' <2> doesnt work <1> _ke: you do realize that sed sees new line only if 'N' (or similar) have been p***ed to it? if you still can't get it to work can you post sample data and desired output? <1> (your sed implementation/version and OS might be relevant) <2> GNU sed version 4.1.5, linux <2> sample data: <2> FN:Lukas Pirpamer <2> = 1986/03/13 <2> there is a \n after "Pirpamer"
<1> _ke: yes there is, but you have to make your sed see it. <1> 14:53:29 age $ echo -e 'FN:someone\n= birth date' | sed 's/\n//' <1> FN:someone <1> = birth date <1> that is a no-go. if you add 'N;' before the s/// it will work. <2> thanks <1> when sed sees a line, it strips the new line char from it. that is why simple s/\n// doesn't work. N tells sed to append new line char to current pattern space and than to append next line to pattern space. in this way sed sees the new line char and can remove it <2> gotcha <3> How to match the text between two " and print it out? <1> honschu: can the text between " span across several lines? <3> oh no <1> honschu: can there be several "" pairs in a single line? <3> I would like to process a list of games that is generated by "xmame.x11 -lf" which prints out lines like: puckman "PuckMan (Japan set 1)" <3> no, only one <3> puckman "PuckMan (Japan set 1)" <3> ^ or something like that <1> honschu: ah, than it is easy: s/.*"\(.*\)".*/\1/ <3> wow, thanks a lot - I'll try it <3> ? I don't understand this: If I type the following line in my bash, I get one '1' in a lot of lines: <3> sed s/.*"\(.*\)".*/\1/ gamesLFsorted.txt <1> sed 's/.*"\(.*\)".*/\1/' file.txt <3> that's it! very cool - and THANK's a lot. <2> redduck676, one small question: i use that for deleting a new line when the line ends with a digit: sed -e :a -e '/\([0-9]\)$/!N; s/\n/ /; ta' <2> but the result is: = 29/05/1990ewein instead of max ohnewein = 29/05/1990 <4> _ke: if a line ends with a backslash, append the next line to it sed -e :a -e '/\\$/N; s/\\\n//; ta' <4> _ke http://www.student.northpark.edu/pemente/sed/sed1line.txt AND sed.sf.net <2> gnubien, it works when i execute that command and insert some text, but it does not when i do: cat file.txt | command .... <4> _ke: happens, best to use this syntax: sed -e :a -e '/\([0-9]\)$/!N; s/\n/ /; ta' filename <2> gnubien, no.. same thing <4> post your command that does not work <2> sed -e :a -e '/\([0-9]\)$/!N; s/\n/ /; ta' filename <4> is it a txt file? <2> yes <4> is it a dos or other OS file? <2> unix <4> grep for your regex in the file and look for anything unusual <2> ok
Return to
#sed or Go to some related
logs:
#javascript remove sendmail + ubuntu ubuntu shared key restricted interfaces #linux #perl wmvd .dll ubuntu sudo: unable to lookup filter via gethostbyname() suse downgrade yast #css #css
|
|