[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]
4chanarchives logo

grep/sed

  1. Home
  2. Board: /g/ - Technology
  3. Reading: grep/sed

Thread replies: 5
Thread images: 2

File: 1466732852437.jpg (4KB, 238x195px) Image search: [Google] [Yandex] [Bing]
1466732852437.jpg
4KB, 238x195px
I'm so sick and fucking tired of the shitty sed and grep regex syntax. So i'm sharing a piece of Java code.

import java.io.*;
import java.util.regex.*;

public class Jsed{

public static void main (String args[]) {

Pattern p = Pattern.compile(args[0]);

try {

InputStream in = System.in;
ByteArrayOutputStream out = new ByteArrayOutputStream();

byte[] buf = new byte[4096];
int b;

while ((b = in.read(buf)) != -1) {
out.write(buf, 0,b);
}

Matcher m = p.matcher(new String(out.toByteArray()));

while (m.find()) {
System.out.println(m.group(1));
}

} catch(IOException io){
io.printStackTrace();
}
}
}


This enables you to use Java's Regex system in a pipe. For ex.

thinkpad :: ~/Documents % tree -if | jsed "(.*\d+_\d+_\d+.*\.jpg)"
./instagram/122252_161113958834_185772_n.jpg
./instagram/108184_164011148759_1532867_n.jpg
./instagram/122913_163463958699_13906354_o.jpg
./instagram/130322_151904900462_226310_n.jpg


Thank me later.
>>
Stealing this and posting on my git claiming I made it.

Thanks for the job OP!
>>
>>55481930
>adding java to your portfolio
You love being unemployed, don't you?
>>
File: IMG-20160703-WA0006.jpg (51KB, 750x729px) Image search: [Google] [Yandex] [Bing]
IMG-20160703-WA0006.jpg
51KB, 750x729px
This is pretty cool op
>>
>>55481960

>implying java isn't the most in demand language

nice b8 m8.
Thread replies: 5
Thread images: 2
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK