Tag Info

Hot answers tagged

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

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

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

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

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


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


1

Probably but you'll need some manual work. xslx files are in fact ZIP files with XML data in them. SO just unpack the file and have a look inside. The format isn't something a sane mind will easily understand but it should be possible to open the sheet files, look for the Row elements and strip everything after the first few hundred. Alternatively, you can ...


1

awk ' {user = $1; $1 = ""; users[$0] = users[$0] sep user; sep = " "} END {for (key in users) {print key ">" users[key]}} ' Given your sample input, this produces ALL = NOPASSWD:/usr/bin/pwdadm,/usr/bin/chsec,/usr/bin/chuser>tom jim mark peter


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

Here it is in Perl: perl -ne '$_ =~ s/([a-zA-Z0-9]+_){3}//; print $_;' For example: % echo "username_token1_token2_token3_4_token4_2" | perl -ne '$_ =~ s/([a-zA-Z0-9]+_){3}//; print $_;' token3_4_token4_2 Works as follows: Initially the string "username_token1_token2_token3_4_token4_2" is put into the $_ variable. search and replace s/....// ...


1

Mendeley should be able to do this. It can import PDFs and then export the metadata to BibTeX, RIS and EndNote XML. It is free to download and is cross-platform. Edit: I tested this on a few documents. The PDF import does seem to work well for references that are formatted correctly. For a document I created using LaTeX, all of the references with the ...


1

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


1

If you can parse the output with some other utility to get the filename and line number, you can easily open that file with the cursor on the specified line by doing: emacsclient +LINE_NUMBER FILE_NAME This should cause emacsclient to take the nearest buffer and replace it with FILE_NAME at LINE_NUMBER.


1

(x-get-selection) is an elisp function that returns the current X11 selected text. Also, the standard way to get an error message and use it in emacs to be able to jump directly to the specified file/line is to run M-x compile, or use a command that customizes compilation mode. emacs already recognizes gcc, g++, and many other programs' output. With M-x ...


1

You don't say how you read your email (offline, webmail) and what mail provider or software you are using, but here some pointers: you can use procmail if your mail servers provide it or you can do this on your client side alternatively this can be done in many email readers If this doesn't apply find a mail provider that has procmail support and move ...


1

On Windows, it's only the extension that makes file executable - to be specific EXEs will execute and some other formats will be interpreted by cmd or PowerShell. On Unix-like systems, there's an execution bit. If you're familiar with the concept of Windows file attributes, then you can think of it as of a kind of attribute. Any file can have an execution ...


1

traditionally, you download the pages HTML, and look for some constant that immediately precedes your data. unfortunately your question does not have a universal answer since every site is different. I've written scripts in python, Bash, and even C# that pull down a page, search it for the tag I want, and extract it. Take a look at the pages source, and ...


1

You can try to scrape a page using Javascript (in form of a Greasemonkey script / Userscript / an extension / a bookmarklet / ...). The bookmarklet means that you have to jump manually to that page and execute it. The other methods allow for passing the data straight to your database (local storage when using a privileged extension or a web server). Writing ...


1

Here is quick and dirty awk hack: awk -F "'" '{print $4}' wp-config.php You can also try cut: cut -d"'" -f 4 wp-config.php EDIT: to set variables this should work: USERNAME=`grep DB_NAME wp-config.php | awk -F "'" '{print $4}'` And so on..


1

If you really just want the video ID – so, anything between v= and the next & – just use: sed -r 's/.*v=([[:alnum:]]*).*/\1/' Here's what's wrong with your command: The -r is needed to use extended regular expressions. If you leave that out, sed interprets the parentheses literally, so there won't be any match groups. With BSD sed, use the -E option ...


1

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


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



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