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

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 ...


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


5

This script should do the job: dir | %{ $id = $_.Name.SubString(0,8); if(-not (Test-Path $id)) {mkdir $id}; mv $_ "$id\$_";} Explanation: foreach file in the directory (% is an alias for foreach): Get the id from the first 9 characters. Note that the $_ variable is an automatic variable populated by powershell that represents the ...


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

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)) ...


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 ...


3

Use the -o option: grep -E -i -o "we'[a-z]+" file.txt Note that this is not universally portable to all grep implementations, though.


3

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 ...


3

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. ...


3

Maybe not more elegant, but shorter, and with the same problem as yours regarding case sensitivity. Problems if the school ending string is not consistent, but perhaps they are. =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(J2,"Elementary",""),"Middle School",""),"High School","") Someone may create a more elegant user defined function, but you could add this to a ...


3

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


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.


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

You say you need to do it "in Bash", but you seem to mean "in a script" and not "using pure Bash syntax" (there is a difference). I assume you want the "in a script" meaning. If you have saved all the links on separate lines in a document, you can pick out all links on the domain http://www.example.com/ with e.g. grep "^http://www\.example\.com/" ...


3

And here's a nice, simple gawk one-liner : $ gawk '{if(match($0, /^\[ (.+?) \]/, k)){name=k[1]}} {print >name".txt" }' entry.txt This will work for any file size, irrespective of the number of lines in each entry, as long as each entry header looks like [ blahblah blah blah ]. Notice the space just after the opening [ and just before the closing ]. ...


3

Yet another awk solution: BEGIN { RS="\\[ entry[0-9]+ \\]\n" # Record separator ORS="" # Reduce whitespace on output } NR == 1 { f=RT } # Entries are of-by-one relative to matched RS NR > 1 { split(f, a, " ") # Assuming entries do not have spaces print f > a[2] ".txt" # a[2] now holds ...


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 ...


2

Is it not simpler to use existing commands? Not everything needs a new program. csplit /\[/ file


2

The following perl script does the job: #!/usr/bin/perl while (<STDIN>) { if ($_ =~ m/^\[ (.+?) \]/) { $f = $1; close FH if tell(FH) != -1; open FH, ">", "$f.txt" or die "couldn't open file $f: $!\n"; } print FH $_; } close FH; Run the script like this: script.pl < entry.txt The script works no matter how ...


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

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

You can use a combination of RIGHT and LEN. ="https://twitter.com/"&RIGHT(A17,LEN(A17)-1) Alternatively, you can use SUBSTITUTE to the same effect. ="https://twitter.com/"&SUBSTITUTE(A1,"@","") SUBSTITUTE may be a better option if the formatting of the Twitter handles in column A is inconsistent at all.


2

What exactly does not work for you with grep? Try looking at cut command. You are looking at something like: grep YourFileNameHere -e "| Name |" | cut -d " " -f 4 this should parse YourFileNameHere and look for the line containing | Name | then pipe that line to the cut command that will pick the 4th token between (space) delimiters, which according ...


2

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, ...


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 need "xyz" try this (GNU sed): echo 'http://www.youtube.com/watch?v=abc&g=xyz' | sed 's/.*=\([[:alnum:]]*\).*/\1/'


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 ...



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