unix-programming

'Quick' Shell Scripting Help

I need help with this shell script. Must use a loop of some sort. Must use input data exactly as shown. Output redirection should be accomplished within the script, not on the command line. Here's the input files I have: http://pastebin.com/m3f783597 Here's what the output needs to be: http://pastebin.com/m2c53b25a Here's my failed...

Access a variable in a bash script

In the bash command line, I set a variable myPath=/home/user/dir . I created a script in which I put echo $myPath but it doesnt seem to work. It echoes nothing. What can I do to access the myPath variable in the script. If I write echo $myPath in the command, it works, but not in the script. ...

parse an email message for sender name in bash

I have multiple files in a folder and each of them have one email message. Each message has a header in the format Subject: formatting fonts To: [email protected] From: sender name message body I want to get all the unique sender names from all the messages (there is only 1 message per file) . How can I do that? ...

How can I collate and summarize records from a file with Perl?

Hello all, I have a text file in the following format: 211B1 CUSTOMER|UPDATE| 211B2 CUSTOMER|UPDATE| 211B3 CUSTOMER|UPDATE| 211B4 CUSTOMER|UPDATE| 211B5 CUSTOMER|UPDATE| 567FR CUSTOMER|DELETE| 647GI CUSTOMER|DELETE| I want a script that processes the text file and reports the following: "UPDATE" for column CUSTOMER found...

Challenges in writing wrappers for C++ functions so that they can be used from C code

I am now writing wrappers for C++ functions, such that they can be used from C code. The idea is to compile the cpp files using g++ and the c files using gcc, then link them together (!), but exposing ONLY those functions that are needed, to the C programs, by making them available in a header file 'test.h' (or maybe test.hpp?), like so...

How can Unix pipes be used between main process and thread?

I am trying to channel data via pipes whenever a signal arrives from a thread to the main process. Is this possible? How can this be done? The problem: A child thread reads data and puts it into a queue. Main application does its own stuff, however, when data is available on the queue, it should be notified by the thread, and st...

What are the differences between poll and select?

I am referring to POSIX standard of select and poll system C API calls? ...

Can the signal system call be used with C++ static members of the class?

Is the following supported across *nix platforms? #include <cstdio> #include <sys/types.h> #include <signal.h> #include <unistd.h> class SignalProcessor { public: static void OnMySignal(int sig_num) { printf("Caught %d signal\n", sig_num); fflush(stdout); return; ...

How can I put a pointer on the pipe?

Say I have a pointer to some structure in a thread, and I want to pass it to the parent process via a pipe. Example: MyType * someType; I then want to cast someType to void * and put it on the pipe. How can it be done? ...

How can I pass data from a thread to the parent process?

I have a main process that uses a single thread library and I can only the library functions from the main process. I have a thread spawned by the parent process that puts info it receives from the network into a queue. I need to able to tell the main process that something is on the queue. Then it can access the queue and process the ...

Why do I need to close fds when reading and writing to the pipe?

Here is an example to illustrate what I mean: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(void) { int fd[2], nbytes; pid_t childpid; char string[] = "Hello, world!\n"; char readbuffer[80]; pipe(fd); if((childpid = fork()) == -1) { ...

How can I express 10 milliseconds using timeval?

How can I express 10 milliseconds using timeval? This is what I have so far: struct timeval now; now.tv_usec =10000; ...

comparing lists and finding unique entries

Hello, I have two lists of names, A and B. I need to produce three lists: 1) names only on A 2) names only on B 3) names on both A and B I also have a list with all the names on A and B, C. Can anyone think of Unix tools or quick scripts to do this? ...

Performing an operation at an interval

I want to perform the action at a certain timeout, like fire an event. I figured out how to do every n number of seconds, but not 1.5 seconds. Here is what I have. Please suggest how to handle my case: void Publish() { static int local_time=time(NULL); int current_time = time (NULL); if((current_time+PUBLISH_TIMEOUT)>loc...

Is there any C++ api available to know the OS description?

I am working tools that will be used on the multiple OS and platform. This tools will provide the details of the OS on which it is running, like 32 bit or 64 bit OS, exact version of Linux,Solaris,or other OS. One way I am thinking of using the "uname -a" command to extract the OS information on the Linus/Unix based OS. Please suggest m...

unix manual programs

shell script to generate a multiplication table. ...

Fork and sighandlers

If I setup sighandler and then do a fork. Will the child process also inherit the sighandlers? ...

Suggested reading order and other questions....

Based on recommendations from episode 57 of the StackOverflow Podcast, I have purchased "Structure and Interpretation of Computer Programs", "The C Programming Language", "Unix Programming Environment", and "Introduction to Algorithms". I'm wanting to improve my fundamental programming skills, contribute to some open source projects, and...

UNIX nonblocking I/O: O_NONBLOCK vs. FIONBIO

In every example and discussion I run across in the context of BSD socket programming, it seems that the recommended way to set a file descriptor to nonblocking I/O mode is using the flag to fcntl(), e.g. int flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); I've been doing network programming in UNIX for over te...

What debugger tools do you use to look at contents of a STL container (on linux)

I use gdb (actually DDD), and getting an element out of container is impossible. So I typically end up rolling my own loop for debugging purposes... What do you do? ...