Tag Info

Hot answers tagged

6

Exposition -- trying to directly answer the question If you are reading the source code for an emulator and it is not reading certain bits of a binary (executable) file and is still faithfully executing the code, then there are three possible outcomes: You are wrong in thinking that the emulator does not read every bit of the file, and it in fact does, ...


5

There's a few methods to parse command line arguments. Assuming you're using bash, the least painful way is probably using getopts. For example: #!/bin/bash while getopts "abc:" flag do echo "$flag" $OPTIND $OPTARG done [~]$./ssc.sh -ab -c file a 1 b 2 c 4 file


4

In order to use non-greedy regexes with grep you will need to use the -P option and the -o option outputs only the matching portion. You will also need to use lookarounds so that part of the match is not included in the output. grep -Po '.*?//\K.*?(?=/)' Example: $ echo 'hxxp://subdomain.url3.com/somepage.php' | grep -Po '.*?//\K.*?(?=/)' ...


4

Try this OLDIFS=$IFS IFS=' ' typeset -a file file=($(cat list.txt)) for i in "${file[@]}"; do echo $i >> ${i:0:1}.txt done IFS=$OLDIFS Note, the IFS part is not usually necessary. Also, I tested it on Zsh 4.3.17 on linux and on Bash 4.2.37. What it does is it declares an array, assigns the contents of the file to that array, then loops over ...


4

You could just use gawk and simplify things: gawk '{n=substr($1,0,1); print >> n".txt"}' file.txt n=substr($1,0,1) takes a substring of length 1 starting from the first position (0) of the first field ($1) and saves it into a variable called n. print >> n".txt" will append (>>) each line into a text file called n.txt (where n is the ...


3

In notepad, you can type Ctrl+g to view current line number. It also at bottom-right corner of status-bar.


3

This can be done natively in Windows, using the command prompt: find /c "string to find" "mytextfile.txt" findstr is more advanced (supports regex) but doesn't support printing line count. You could pipe its output to find: findstr "string to find" "mytextfile.txt" | find /c /v "" find /c /v means count lines not containing. From testing, the empty ...


3

What does the backslash (\) do over here? grep uses an "escaped" pipe (|) to mean logical OR. In other words, grep 'foo\|bar' means print any lines that contain either "foo" or "bar". What do the pipes "|" in between do? See answer to 1. Why is "content\|" in double quotes? It is not. The quotes are part of the pattern being searched for, the output of ...


3

Untested: t=`basename $f | sed -e 's/-[0-9]\+$//'`


3

You can do this in VBA with the vba-json library. Here's an example of some code I copied: Sub TestJsonDecode() 'This works, uses vba-json library Dim lib As New JSONLib 'Instantiate JSON class object Dim jsonParsedObj As Object 'Not needed jsonString = "{'key1':'val1','key2':'val2'}" Set jsonParsedObj = lib.parse(CStr(jsonString)) ...


3

Her's a link to download ArcReader, and an explanation: http://crawler.archive.org/articles/developer%5Fmanual/arcs.html. I Googled for reading arc files and this was the first link. First you need to unzip the files (they are gzipped, hence the .gz extension.). Then you can read the ARC file.


2

Try a tool such as Regex Buddy or Expresso. If you're not a programmer Regular Expressions may be a bit intimidating, but they're really not that hard, especially with a decent tool like one of the above. Here's an example of someone using Regular Expressions for extracting citations: Citation parsing regular expression


2

Calibre does most ebook related conversions including this one. There is also ConvertLit which is an executable that expands one .lit file but can be wrapped in a batch script. Both work on most OSs


2

Perl's XML::Twig comes with... xml_grep --nowrap --text_only /statuses/status/text In XML::XPath you can do: perl -MXML::XPath -E 'my $xp = XML::XPath->new(ioref => \*STDIN); say $xp->getNodeText("/statuses/status/text");' or perl -MXML::XPath -E 'my $xp = XML::XPath->new(ioref => \*STDIN); for my $node ...


2

Even simpler, if you just want the abc: echo 'http://www.youtube.com/watch?v=abc&g=xyz' | awk -F'[=&]' '{print $2}' If you want the xyz : echo 'http://www.youtube.com/watch?v=abc&g=xyz' | awk -F'[=&]' '{print $4}' EXPLANATION: awk : is a scripting language that automatically processes input files line by line, splitting each line ...


2

It sounds like the lines are intended to be unique and order doesn't matter, so try this: sort fileA > fileA.sort sort fileB > fileB.sort diff fileA.sort fileB.sort | sed -n "/^</{s/< //;p}"


2

If you wanted to use code to do this you can do it in Perl using LWP::Simple or Mechanize modules. The following might have what you are after Find All Links from a web page using LWP::Simple module This is assuming you are comfortable with using a command line solution using Perl. This works the same on both Windows and Linux platforms. It wouldn't take ...


2

Yep, it's a good ol' bash script. This uses the lynx browser to extract the URLs from the pages and dump them to a text file: #!/bin/bash # # Usage: # # linkextract <start> <end> <pad> <url> # # <start> is the first number in the filename range. Must be an integer # <stop> is the last number in the filename range. ...


1

Lines that only exist in fileA: comm -23 <(sort fileA) <(sort fileB) > output.txt All lines unique to fileA will be saved in the file output.txt.


1

Experimenting with sed based off the answers given by @Endoro and @slhck led me to the final answer (the one I wanted). This is what works for me with the version of sed on Mac OS X (10.7.5): echo 'http://www.youtube.com/watch?v=dnCkNz_xrpg' | sed -E 's@https?://(www\.)?youtube.com/(watch\?).*v=([-_a-zA-Z0-9]*).*@\3@' Explanation: -E is to make sed use ...


1

You can trim out portions of the string, based on finding the "x" in your string. Will this be for only one cell or many? To get things started with how the trimming could be accomplished: assuming the string is in cell A1, and you want the first part of the dimension in B1, you could put this formula in B1: =LEFT(A1,LEN(A1)-(FIND("x",A1,1)+2)) The LEFT ...


1

A simple solution is for /f "tokens=3" %%a in (database.txt) do set word3=%%a After this statement, the variable %word3% will contain the third word from the line in the file.  If the file has more than one line, you will get the third word from the last line that has at least three words; the set word3=%%a command (after the do keyword) will be executed ...


1

My question is, if the emulator must emulate the exact opcodes that the real CPU would, wouldn't it be required to parse the correct binary opcode format of a game to emulate the CPU legitimately(or at all)? "Parse" means "go through text and figure out what stuff means." Text and language-like syntax is complex because not only do individual "words" ...


1

there was imho a syntax error in /usr/share/perl5/iCal/Parser/HTML.pm. the following line foreach my $t qw(week month year) { has to look like this foreach my $t (qw(week month year)) { now everything works fine.


1

/^SENDER=\([*]*\)$/s//\1/p [*] What a kind of syntax is that? Any char is . in regexps. $ sed -n '/^SENDER=\(.*\)$/s//\1/p' <<< SENDER=xpto@xpto.bar xpto@xpto.bar But I doubt you’ve chosen a right way to do what you are doing. What for do you need this? Most probably, it would be much better to read the whole config in array. ...


1

You can use the Site Visualizer crawler for this work. Download and install it, then click New Project, type your website's URL, click OK, then Start Crawl toolbutton. After the crawling is completed, double-click All Links report of the Reports tab. You'll be given all links that are present on the website, as well as other info: source/target link URLs, ...


1

I'd just use regex in the shell or in some shell scripting language: paragraphs of (do shell script "/bin/echo " & quoted form of "<p class=\"new\">yyy</p><p>uuu</p>" & " | ruby -e 'puts $<.read.scan(/<p.*?>(.+?)<\\/p>/)'")


1

This shell code will concatenate segments of the input until they form a valid file (path) name: file="" sep="" for word in $path do file="$file$sep$word" if [[ -f "$file" ]] then break fi sep=" " done echo "first file: '$file'" This assumes that the named files already exist (and your script can "see" them; i.e., can search ...


1

some solutions: awk -F_ '{ print $5"_"$6"_"$7"_"$8 }' . awk '{ print gensub("^.*_([^_]+_[^_]+_[^_]+_[^_]+)$", "\\1", "g") }' . awk '{ if (match($0, "_([^_]+_[^_]+_[^_]+_[^_]+)$", a)) print a[1] }'


1

sed 's/^[^:]*:[^_]*_[^_]*_[^_]*_//'



Only top voted, non community-wiki answers of a minimum length are eligible