Tag Info

New answers tagged


Here's a variant on glenn's answer that will work if you have multiple consecutive occurrences (works with GNU sed only): sed ':x /"line"/N;s/"line"\n<second>/other characters/;/"line"/bx' your_file The :x is just a label for branching. Basically, what this does, is that it checks the line after substitution and if it still matches "line", it ...


Three different sed commands: sed '$!N;s/"[^"]*"\n<[^>]*>/other characters /;P;D' sed -e :n -e '$!N;s/"[^"]*"\n<[^>]*>/other characters /;tn' sed -e :n -e '$!N;/"$/{$!bn' -e '};s/"[^"]*"\n<[^>]*>/other characters /g' They all three build on the basic s///ubstitution command: s/"[^"]*"\n<[^>]*>/other characters / ...


read the whole file and do a global replacement: sed -n 'H; ${x; s/"line"\n<second>/other characters /g; p}' <<END first "line" <second> line followed by "line" <second> and last END first other characters line followed by other characters and last


Well, I can think of a couple of simple ways but neither involves grep (which doesn't do substitutions anyway) or sed. Perl To replace each occurrence of "line"\n<second> with other characters, use: $ perl -00pe 's/"line"\n<second>/other characters /g' file first other characters line and so on Or, to treat multiple, consecutive occurrences ...


sort -dk2,2 phpbook | sed "s/\t/\n/3;s//\n/2;s// /g" As I understand it you have a file called phpbook that consists of lines of phone book entries that look like this: {first}\t{last}\t{address}\t{city}\t{state}\t{zip} You want to sort these on {last}, add newlines following {last} and {address} for each entry, translate \tabs to <spaces> and ...


I think this part of the paste man page is what you want: -d, --delimiters=LIST reuse characters from LIST instead of TABs So this one-liner should work for your case: paste -d" \n\n " tmp1 tmp2 tmp3 tmp4 tmp5 tmp6 > tmp7 Works as expected with @DopeGhoti's sample data: $ grep . tmp* tmp1:Bill tmp1:Bob tmp2:Kerman tmp2:Germin ...


Try this solution with two extra temporary files: paste tmp1 tmp2 > tmp12 paste tmp4 tmp5 tmp6 > tmp456 paste -d "\n" tmp12 tmp3 tmp456 > tmp7 This solution was based on the assumption that the -d option selects the delimiter globally for all input files so it either be a blank or a newline. In a way this is true since later occurences of -d ...


You might get by combining paste and awk: paste -d'|' tmp1 tmp2 tmp3 tmp4 tmp5 tmp6 | awk 'BEGIN { FS = "|" }; {print $1, $2 "\n" $3 "\n" $4, $5, $6}' > tmp7 Example output from some test data I threw together for the tmp files: Bill Kerman 123 Main St. Kerbopalis Kerbskatchewan 12345 Bob Germin 321 Sesame St. Kerbington Kermont 31416


This command should work. paste -s tmp1 tmp2 -d '\n' tmp3 -d '\n' tmp4 tmp5 tmp6 > tmp7


To recursively sanitize a project I use this oneliner: for f in $(find . -type fls); do tail -n1 $f | read -r _ || echo >> $f; done


The problem with the script is that when copying a file from another system like Windows, it adds a newline \n and a carriage return \r\n. For more about line feeds see newline entry on wikipedia. To demonstrate the issue I've uploaded short fragment here which explains how to solve the problem. In short: Use tr to remove those weird line endings tr -d ...


what about using ed? This one saved my day: http://wiki.bash-hackers.org/howto/edit-ed This is how to do it: ed -s test.txt <<< $'/fruits/s/apple/banana/g\nw'


You saved the files being sourced with DOS line endings (CRLF). Your editor automatically recognizes this and doesn't show the ^M characters, but they're still there. (It probably has some other indicator that the file uses DOS line endings.) You need to remove the CR characters. One way is this: perl -pi -e 's/\r//' /home/rob1nn/.r_inc/*

Top 50 recent answers are included