unix

How can I use the UNIX shell to count the number of times a letter appears in a text file?

I have a few text files and I'd like to count how many times a letter appears in each? Specifically, I'd like to use the UNIX shell to do this, in the form of: cat file | .... do stuff... Is there a way I can get the wc command to do this? ...

Wait for a Unix Domain socket to be bound

I am writing a client app which connects to a server process through a Unix domain socket. If the server process is not running, I want the client to wait until the server has started and is listening for connections on the socket. Currently I have a retry loop in the client which calls connect() every second until it successfully conne...

Developping for iphone under unix

Hi guys My question is very simple : Is there any solution to install xCode, or equivalent, under unix OS, like ubuntu ? Indeed, i don't want to buy an expensive macbook to develop my private iPhone applications. Thanks for your hints. Martin ...

Buffering filtering pipe on Linux

I commonly build up long, multi-command pipes on Linux/Unix to process large text files (sed | grep | sort | less , etc.). I would like to be able to use a pipeline element that would buffer everything received via stdin until a key phrase/string is detected (e.g. "SUCCESS"), at which point it releases everything received up to that poi...

simple shell script in cygwin

#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie to shell scripting. I am trying to run the above script in cygwin. I want to be able to write one line after the other to a new file. However, when I execute the above script, I see the follwoing contents in foo.xml: second line The second time...

Determine if C library is installed on Unix

As a follow up question to my last one, is there any simple way to tell if a given C library is installed on a given machine (not programattically, just as a once off sort of thing)? I need to use libuuid, but I'm not sure if it's installed on the machines in question. The only two ways I can think of are: 1) Try to compile the code t...

Korn Shell - Date validation in script

I'm trying to do validation of a date entered as numbers only. (e.g. 09042009 as 09/04/2009) The code now just checks the length of the date. How would I validate not only length of the date entry but also that it is a real date? What would be the syntax for combining tests and regular expression? Code as it exists now: echo "Plea...

Multiple fork() Concurrency

How do you use the fork() command in such a way that you can spawn 10 processes and have them do a small task concurrently. Concurrent is the operative word, many places that show how to use fork only use one call to fork() in their demos. I thought you would use some kind of for loop but i tried and it seems in my tests that the fork()...

Java Application NoClassDefFoundError

Created a Java application to upload documents via CIS (Content Integration Suite) to a storage application. The app runs successfully in RAD, but as a executable jar in a unix environment, getting a NoClassDefFoundError. I can not find the class on my local machine and there are not references to the class on the internet. The mani...

Resources to learn MacOSX development from Linux/Windows development point of view

I have programmed a lot on Linux, and to some extent on Windows. Even though MacOSX is fundamentally based on the BSD kernel, there are quite a number of user-level services and APIs that I am not fully knowledgeable about (plist, .app bundles, universal binaries, etc..). Is there a resource (preferably book) that you would recommend L...

Unix - "xargs" - output "in the middle" (not at the end!)

Hello, example use of "xargs" application in Unix can be something like this: ls | xargs echo which is the same as (let's say I have "someFile" and "someDir/" in the working dir): echo someFile someDir so "xargs" take its "input" and place it "at the end" of the next command (here at the end of echo). But sometimes I want xargs to...

issues with expect -send: spawn id exp4 not open

My expect code does this: It does a ssh connect to another machine, sends the password and then returns the hostname of that machine. I give a sample of my code below #!/usr/bin/expect -f set ipaddr [lrange $argv 0 0] set password [lrange $argv 1 1] set timeout -1 spawn ssh root@$ipaddr hostname match_max 100000 expect "*assword:*" send...

using rsync to backup mysql

hi, I use the following rsync command to backup my mysql data to a machine within the LAN network. It works as expected. rsync -avz /mysql/ root:[email protected]:: /root/testme/ I just want to make sure that this is the correct way to use rsync. I will also like to know if the 5 minute crontab entry for this will work. ...

On a Mac, within the shell, how can I tell that I have a GUI?

Because you (lovely) people are always so curious about posters' original intents, here's mine: If I'm on a Mac and have a GUI (as opposed to, say, being on an ssh session), I want to set my $EDITOR to mate_wait. (And go with vim otherwise.) And, you have an answer for that. I do too. It even works. Here. Sometimes. So I want you...

Using Awk to process a file where each record has different fixed-width fields.

I have some data files from a legacy system that I would like to process using Awk. Each file consists of a list of records. There are several different record types and each record type has a different set of fixed-width fields (there is no field separator character). The first two characters of the record indicate the type, from thi...

Octave + GNUPlot + Aquaterm + Mac OS 10.6 -- Student Needs Help!

Greetings, I'm the only person in my Numerical Analysis class attempting to do all of the MatLab based homework assignments in Octave - the opensource representation of MatLab. However, I'm having problems getting graphs to plot and I think it's a simple linking problem. I am running: -Mac OS X Snow Leopard (10.6) -Octave 3.2.2 -Aqua...

How can a currently running C program find out what directory it is located in?

Say I have a command line C program which is currently executing, and I want to read a file or execute another binary in the same directory - how can I find out what directory that is? Note that I'm not looking for the current working directory. The user may have invoked my original program in any of the following ways (and possibly oth...

Validating Variables in Shell Script

What is the best way to make sure that all the environment variables I need for my script have been set? Currently, I have multiple if-statements which is not very neat: if [ -z "$VAR1" ] then echo VAR1 not set exit fi if [ -z "$VAR2" ] then echo VAR2 not set exit fi if [ -z "$VAR3" ] then echo VAR3 not set exi...

Releasing reources in Windows and unix

Hello, I want to know when I am programming an application, say both unix and windows. If program stops (got an exception), what resource I should release ? objects on the head ? DB connections ? file descriptions ? shared memory ? If I am not mistaken unix releases all except from shared memory and temp files, right ? Is there some...

question about UNIX dig output

Using the unix dig command, I can get the following MX record: $ dig +nocmd gmail.com MX +noall +answer gmail.com. 1868 IN MX 20 alt2.gmail-smtp-in.l.google.com. gmail.com. 1868 IN MX 40 alt4.gmail-smtp-in.l.google.com. gmail.com. 1868 IN MX 5 gmail-smtp-in.l.google.com. gmail.com. 1868 IN MX 10 alt1.gmail-smtp-in.l.google.com....