Tag Info

Hot answers tagged

5

Using awk: awk ' BEGIN { fields[1] fields[3] fields[4] fields[5] fields[6] fields[7] last_field=8 } ( NR%21 in fields ) { printf($0",") } NR%21==last_field' in_file.txt Or better yet: awk ' NR%21 ~ /^(1|3|4|5|6|7)$/ { printf($0",") } NR%21==8' in_file.txt GNU sed has a nice extension to match the nth line after a ...


5

Your problem is that you try to enter C code into a shell prompt, this doesn't work for obvious reasons. You could either put it into a correct C file, compile it and get a valid binary you could execute: #include <linux/kd.h> #include <sys/ioctl.h> #include <fcntl.h> #include <unistd.h> #include <err.h> #include ...


4

cat file.txt | grep -o -P '.{0,20}string.{0,20}' This should do it for you Update: If you don't want to cat, you can just use the grep with the file as a parameter: grep -o -P '.{0,20}pseudomonas.{0,20}' FileName.html Hope it helps Also, The -P uses Perl Regex, which the man pages says is experimental, if you want to avoid that flag, you could just ...


4

You can only use mv to move multiple files to a single directory in on call. One option here is to use prename (rename is linked to this on most systems, but not all): prename -n 's/download$/html/' -- *.download Remove -n when you are sure this is doing what you want. Another way is simply to use a loop: for file in *.download; do mv -i -- "$file" ...


3

In the OSX 1.9 pppd source code, I found this in Helpers/pppd/pppd.h: #ifdef __APPLE__ #define EXIT_TERMINAL_FAILED 20 #define EXIT_DEVICE_ERROR 21 #endif #ifdef MAXOCTETS #ifdef __APPLE__ #define EXIT_TRAFFIC_LIMIT 22 #else #define EXIT_TRAFFIC_LIMIT 20 #define EXIT_CNID_AUTH_FAILED 21 #endif #endif #ifdef __APPLE__ #define ...


3

pcregrep -MnirIso '(?s).{0,20}pseudomonas.{0,20}' . | grep --color -e '^' -e pseudomonas Assumes matches and their context don't overlap and that filenames don't contain pseudomonas. Also note that the reported line numbers are those of the beginning of the context.


3

Here's one way: $ perl -000ne '@f=split(/\n/); print join(",",@f[0,2..7]) , "\n"' file.txt 1500,18,02,09,47,17,45 1501,27,54,28,50,22,03 Explanation: -000 : activates "paragraph mode", it sets perl's field delimiter to \n\n, consecutive newlines. This means that it will treat each of your records as a single line. @f=split(/\n/); : split the current ...


2

That C code would not work anyway -- fdopen() requires more than one argument and returns a file stream, not a file descriptor. I can remember doing this a few years ago, I thought via Xlib, but I could not find my old code (occasionally the collection gets purged) but I figured someone must have a simple app for this on github or something. Low and ...


1

The \+ and \? parts of your sed command are GNU extensions - POSIX compatible sed cannot use these aspects of extended regex at all. Instead you can use \{1,\} and \{0,1\}. Try this: LOCATION='\033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"`' For more information on this see - ...


1

Short story: don't use setuid shell scripts (or any setuid/setgid script). Long story: Allow setuid on shell scripts Solution: invoke the command using sudo. sudo arp -s 198.51.100.1 00:53:00:12:34:56 To allow the user steven to run this command without entering a password, run visudo and add the following line: steven ALL = (root) NOPASSWD: arp -s ...


1

Use Vagrant, it is a layer on top of VirtualBox and provides pre-made images called boxes, amongst them Ubuntu images.


1

mv doesn't work this way. You need another tool like rename or mmv. Please mind that there are two versions of rename around. And, of course, the shell can do that (with mv): for file in *.download; do fbasename="${file%.download}" if [ -e "${fbasename}.html" ]; then echo "${fbasename}.html exists; skipping." echo "${fbasename}.html exists; ...


1

You can view all application dependancies for a file with otool in Mac OS X. Here is an excerpt from the otool man page: The otool command displays specified parts of object files or libraries. For your specific need the following should work: otool -L $(which ctags) For additional files see this answer to a related question on where to look for ...



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