unix

How can I capture the text between specific delimiters into a shell variable?

Hello, I have little problem with specifying my variable. I have a file with normal text and somewhere in it there are brackets [ ] (only 1 pair of brackets in whole file), and some text between them. I need to capture the text within these brackets in a shell (bash) variable. How can I do that, please? ...

When does the write() system call write all of the requested buffer versus just doing a partial write?

If I am counting on my write() system call to write say e.g., 100 bytes, I always put that write() call in a loop that checks to see if the length that gets returned is what I expected to send and, if not, it bumps the buffer pointer and decreases the length by the amount that was written. So once again I just did this, but now that the...

whats your favourite entry in .dbxrc ?

I have started to customize my .dbxrc file to save some time while debugging. What is yours favourite entry in .dbxrc file ? here is mine: export PS1='[ (dbx) Working Hard @ $(date +%H:%M:%S) ]' alias si="stop in" alias attr=attribute alias bfth=stop alias blth=stop alias c=cont alias cv=condition alias d=delete alias e=edit alias h=h...

Launching Ruby without the prefix "Ruby"

I'm on OS X (with bash) and a newbie at unix. I want to know if it's possible to amend some file such that to run a ruby program, I don't need "ruby file.rb", but instead can just run "ruby.rb". Is there a reason NOT to do this? Thanks! ...

How to determine the IP address of a Solaris system

What command do I want to issue when I want to know the IP address of the Solaris machine I'm logged onto? Thanks in advance for any suggestions. --James ...

How do I schedule a process' termination?

I need to run a process, wait a few hours, kill it, and start it again. Is there an easy way that I can accomplish this with Python or Bash? I can run it in the background but how do I identify it to use kill on it? ...

getting hostname with IP

how to get hostname with IP without logging into the host ...

Does cron expression in unix/linux allow specifying exact start and end dates

I want to be able to configure something like this. I want to run job 'X' at 7 AM everyday starting from 29/june/2009 till 30/12/2009. Consider current date as 4/4/2009. ...

How to remove files starting with double hyphen?

I have some files on my Unix machine that start with -- e.g. --testings.html If I try to remove it I get the following error: cb0$ rm --testings.html rm: illegal option -- - usage: rm [-f | -i] [-dPRrvW] file ... unlink file I tried rm "--testings.html" || rm '--testings.html' but nothing works. How can I remove such...

if file is a link on LINUX OS

I am trying to check if a symbolic link exists from korn shell script using "-h filename" command.This works good on HP boxes. Not sure what is the correct option for Linux,AIX and Solaris boxes. ...

Python source header comment

What is the line #!/usr/bin/env python in the first line of a python script used for? ...

Why doesn't my awk one-liner work when I call it from Perl?

Dear all, I have no problem using the following command of AWK as a stand alone command, without any error: $ awk '$9 != "NTM" && $9 != ""' myfile.txt | less -Sn But when I apply them inside Perl's script for qsub (i.e. running job in linux cluster) command, like this: use strict; use Data::Dumper; use Carp; use File::Basename; my...

Replacing String Columnwise Using Sed

Given this data 34 foo 34 bar 34 qux 62 foo1 62 qux 78 qux I want to replace the string at 2nd column into "" if it is "qux". Resulting: 34 foo 34 bar 34 62 foo1 62 78 How do you do that with sed? In particular the data is very big with ~10^7 lines ...

Applying Unix's Head on AWK Through Find Command

I want to output top 10 lines of AWK command in the list of files given by find, using this snippet: $ find . -name "*.txt" -print -exec awk '$9 != ""' \| head -n10 {} \; Note also that I want to print out the file names being processed. But why I get such error: awk: cmd. line:2: fatal: cannot open file `|' for reading (No such fi...

How can I su from root to db2inst1 and invoke a SQL script, in one line?

How can I su from root to db2inst1 and invoke a SQL script all in 1 line? I am thinking about something like this: su db2inst1 | db2 CONNECT TO myDatabase USER db2inst1 USING mypw; db2 -c -i -w -td@ -f /tmp/deploy/sql/My.sql | exit; Any ideas? ...

Allow request coming from specific IP only

I have application hosted Apache UNIX, and I am allowing users to access the application url from citrix environment (from citrix machine). However, currently its possible to access the url from all the connected machines. I would like to put the restriction that it should be only accessed from citrix machine. So if any one needs to ac...

What is an easy way to do a sorted diff between two files?

I have two files in which some of the lines have changed order. I would like to be able to compare these. One website suggested something that looks like this: diff <(sort text2) <(sort text1) But this yields the error: Missing name for redirect. I am using tcsh. Is the command above for a different shell? Is there a better way? ...

using the passwd command from within a shell script

I'm writing a shell script to automatically add a new user and update their password. I don't know how to get passwd to read from the shell script instead of interactively prompting me for the new password. My code is below. adduser $1 passwd $1 $2 $2 ...

How can you move a folder to one folder-level lower?

I have a folder Math at /cs/.../topology/mathematics/Math. I tried the following unsuccessfully at the mathematics -folder. mv Math/ .. How can you move the folder Math to /cs/.../topology/ in terminal? ...

Hide arguments from ps

I would like to keep my ssh command hidden/disguised from other users. Example: ssh user@host -i /my/private/key Unfortunately this will come up in the ps listing and other users will be able to see the private key file that I am using. Is there a way around this? (They are logged in as the same user as I am) ...