shell

Processing a tab delimited file with shell script processing

Hello, normally I would use Python/Perl for this procedure but I find myself (for political reasons) having to pull this off using a bash shell. I have a large tab delimited file that contains six columns and the second column is integers. I need to shell script a solution that would verify that the file indeed is six columns and that t...

Random password variable disappears

Hi, I'm using the following to generate a random password in a shell script: DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8) When i run this in a file on its own like this: #!/bin/sh DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8) echo $DBPASS A password is echoed...

How can I open a Shell inside a Vim Window?

I can open a shell by using the :shell command in Vim, however I can't edit a file and at the same time use the shell. Is there any way to split Vim in many Windows (or tabs), and have a shell opened in one of them? ...

How to define your own terminal tab completions

I've noticed that some programs have their own tab-completion. For example, git: git checkout allows for tab completion of branch names. How is this accomplished? ...

GUNZIP / Extract file "portion by portion"

Hi. I'm on a shared server with restricted disk space and i've got a gz file that super expands into a HUGE file, more than what i've got. How can I extract it "portion" by "portion (lets say 10 MB at a time), and process each portion, without extracting the whole thing even temporarily! No, this is just ONE super huge compressed file, ...

How to use parallel execution in a shell script?

I have a C shell script that does something like this: #!/bin/csh gcc example.c -o ex gcc combine.c -o combine ex file1 r1 <-- 1 ex file2 r2 <-- 2 ex file3 r3 <-- 3 #... many more like the above combine r1 r2 r3 final \rm r1 r2 r3 Is there some way I can make lines 1, 2 and 3 run in parallel instead of one after the anothe...

How portable is mktemp(1)?

As the title suggests — can I be reasonably sure that mktemp will exist on any unix-y operating system I'm likely to encounter? ...

How to resume an ftp download at any point? (shell script, wget option)?

hi! i want to download a huge file from an ftp server in chunks of 50-100MB each. At each point, i want to be able to set the "starting" point and the length of the chunk i want. i wont have the "previous" chunks saved locally (ie i cant ask the program to "resume" the downlaod). what is the best way of going about that? i use wget mos...

Generate a random filename in unix shell

Hello, I would like to generate a random filename in unix shell (say tcshell). The filename should consist of random 32 hex letters, e.g.: c7fdfc8f409c548a10a0a89a791417c5 (to which I will add whatever is neccesary). The point is being able to do it only in shell without resorting to a program. ...

how to add a function to that program, and call that function from the command line in the function

I have to add a custom function which shows currently running foreground and background processes launched by this shell. How do I define and call that function from the shell's command line? a#include "smallsh.h" /*include file for example*/ /*program buffers and work pointers*/ static char inpbuf[MAXBUF], tokbuf[2*MAXBUF], *ptr ...

How to partially ftp a file (using ftp, wget with shell scripts or php)?

hi, i want to partially download a ftp file. i just need to download lets say 10MB, but after skipping 100MB (for example). In php, http://php.net/manual/en/function.ftp-fget.php this function allows arbitay starting point: bool ftp_fget ( resource $ftp_stream , resource $handle , string $remote_file , int $mode [, int $resum...

cd Terminal at a given directory after running a Python script?

I'm working on a simple Python script that can use subprocess and/or os to execute some commands, which is working fine. However, when the script exits I'd like to cd the actual Terminal (in this case OS X) so on exit, the new files are ready to use in the directory where the have been created. All the following (subprocess.Popen, os.sy...

How can I convert a shell script into a Perl script?

How can I convert a shell script into a Perl script? I have a 10k line shell script and want to convert it into Perl. Is there any tool is doing that, or is there any way to do that? ...

PHP system() help

Hello, I have this shell script #!/bin/sh ############################################################# # Example startup script for the SecureTrading Xpay4 client # # Install Xpay4 into /usr/local/xpay4 # # To run this script automatically at startup, place the # # following line at the end of the bootup...

Bash completion for Maven escapes colon

I added bash completion for Maven following the docs: http://maven.apache.org/guides/mini/guide-bash-m2-completion.html Everything works well except for goals that use a colon. For instance, instead of mvn eclipse:eclipse completion escapes the colon mvn eclipse\:eclipse Any suggestions how this can be fixed? I'm using Ubuntu 8.1...

Outlook rule to run VBA script that runs external program

I've set up an Outlook rule that filters for the emails I care about. The action I want to take is to run an external program (python script) to parse each such email. Can someone advise on how to do this? I know of the SHELL function, but I need a way to pass the body of the email to my external program. I have zero experience with ...

Ignoring specific differences in diff

When doing recursive diffs I want to ignore expected differences/translations - is there a way to do that with standard unix tools? E.g. file1: 1 ... 2 /path/to/something/ver1/blah/blah 3 /path/to/something/ver1/blah/blah 4 ... file2: 1 ... 2 /path/to/something/ver2/blah/blah 3 /path/to/something/ver3/blah/blah 4 ... I want to be a...

Help with MySQL (.sql) and Shell Script

How do I call the following in a .sql file? mysql -u username -h serverip db -e "select a, b, c, d from mytable" > '/home/dump/result.txt'; I will then have to convert the tab separated file to csv for which I want to use sed. Is there a way to do it all in one line? (append sed command to convert the .txt file to csv) How to use ...

get the current date and use it in a filename

I'm trying to do something like this: mysqldump --user c1bt3 --password=blah c1bt3 > c1bt{date}.sql where date is replaced with the current date, i.e. c1bt5-11-10.sql, and I'm trying to do it from a linux shell script. Any ideas how I can do this? ...

How can I (from a script) add something to the zsh command history?

I'd like to be able to look through my command history and know the context from which I issued various commands--in other words, "what directory was I in?" There are various ways I could achieve this, but all of them (that I can think of) would require manipulating the zsh history to add (for instance) a commented line with the result ...