Re: Help with sed
Radim wrote: > > What I try to do: > 1) To delete the codecs function of the output. > 2) To get the "if mandriva" block > 3) from that block to get lines of urpmi > > Anybody help? > Or better this: content=$(cat $script | sed '/function codecs/,/fi;/d;/function*\}/p'); # get functions that don't match 'codecs' ... this doesn't work because it shows 1st line only echo $content; # and the next part: content=$(echo $content | sed -n '/mandriva/,/fi;}/p'); content=$(echo $content | sed -n '/^\s*urpmi[:space:]--auto/p'); -- View this message in context: http://old.nabble.com/Help-with-sed-tp28264280p28264345.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Help with sed
Hello, I have such script: (ONLY THIS THREE LINES ARE THE COMMANDS ) content=$(cat $script | sed '/function codecs/,/fi;/d'); content=$(echo $content | sed -n '/mandriva/,/fi;}/p'); content=$(echo $content | sed '/^\s*urpmi[:space:]--auto/p'); But it doesn't work as I would expected. This is the text structure in file, that I need to filter: (THIS IS A TEXT TO OUTPUT! TO FILTER) function codecs { if [ ".." == "mandriva" ]; then urpmi ... ; urpmi ... ; if [ ".." == "kubuntu" ]; then deb ; deb ...; fi; } function name1 { if [ ".." == "mandriva" ]; then urpmi ... ; urpmi ... ; if [ ".." == "kubuntu" ]; then deb ; deb ...; fi; fi; } function name2 { if [ ".." == "mandriva" ]; then urpmi ... ; urpmi ... ; fi; } What I try to do: 1) To delete the codecs function of the output. 2) To get the "if mandriva" block 3) from that block to get lines of urpmi Anybody help? -- View this message in context: http://old.nabble.com/Help-with-sed-tp28264280p28264280.html Sent from the Gnu - Bash mailing list archive at Nabble.com.
Re: Help with sed
The script is already solved on other forum. awk 'BEGIN{RS="\n}";FS="if"} !/function codecs/{ for(i=1;i<=NF;i++){ if($i~/mandriva/){ m=split($i,u,"\n") for(j=2;j<=m;j++) if(u[j]~/urpmi/){print "-->"u[j]} } } }' file -- View this message in context: http://old.nabble.com/Help-with-sed-tp28264280p28279013.html Sent from the Gnu - Bash mailing list archive at Nabble.com.