unix

Extracting data from a file

I have a file results.txt which is like: a.txt {some data} success!! b.txt {some data} success!! c.txt {some data} error!! I want to extract data from it. I want an output like: a.txt: success b.txt: success c.txt: error The problem is that the {some data} part can be arbitrarily long. How can this be done? ...

TUI using slang with pure ascii (7 bit) characters via termcap

I am using newt/snack (a TUI graphical Widgit library for Python based on slang) to have some interactive scripts. However for some target terminals the output of those screens are not very nice. I can change the look of them by changing the $TERM variable to remove non printable characters, and to convert them to something more suitable...

Terminating because of 6 signal

Hi, I compiled and ran my code and got the following error: Terminating because of 6 signal What is signal 6 and what causes it? ...

Awk to replace single quote

Hi I am stuck with this I want to replace all include('./ in a set of files with include('. I am trying to use awk as follows: awk '{gsub("include\('"'"'./", "include\('"'"'", $0); print > FILENAME}' *.php It throws me this error. awk: (FILENAME=xyz.php FNR=1) fatal: Unmatched ( or \(: /include('.// Any help would be appreciated....

How can I quickly close multiple VI instances in different GNU-Screen tabs?

I often have around 10 tabs in GNU-Screen open with all of them having vim open to a different file. If I just kill the Screen session, then VIM doesn't cleanup (.swp files are still there), so I usually have to go to each tab individually and type ":wq" and the "exit" to kill the screen tab. Any faster ways to do this? ...

In-place progress output in the terminal or console

When you run git clone, it updates progress in place. For example, the percentage of the objects received changes in place. user@athena:~/cloj/src$ git clone git://git.boinkor.net/slime.git Initialized empty Git repository in /home/user/cloj/src/slime/.git/ remote: Counting objects: 15936, done. remote: Compressing objects: 100% (5500/5...

What are the differences between .so and .dylib on osx?

.dylib is the dynamic library extension on OSX, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object. Some of the questions I have: At a conceptual level, what are the main differences between .so and .dylib? When can/should I use one over the other? Compilation tricks & tips (For example,...

How to extract the name of immediate directory along with the filename?

I have a file whose complete path is like /a/b/c/d/filename.txt If I do a basename on it, I get filename.txt. But this filename is not too unique. So, it would be better if I could extract the filename as d_filename.txt i.e. {immediate directory}_{basename result} How can I achieve this result? ...

C or C++ for Linux/UNIX daemon programming?

Dear stackoverflow, The topic basically says it all. I want to go more into writing daemons for Linux/UNIX systems and I want things to be fast and stable. Everything I look at seems to be written in C, however, some new projects seem to be using C++ a bit more. So if I were to start my own project, let's say a modular HTTP daemon, whi...

How would I remove all <script> tags (and everything in between) from multiple files using UNIX?

I have a folder with multiple files, and I'd like to remove all <script> tags and everything in between, e.g.: This: <script type="text/javascript">function(foo);</script> As well as this: <script type="text/javascript" src="scripts.js"></script> I think in PHP it would be something like this: <?php $string = preg_replace('#(\n?<...

how do I know if it is Windows server or unix ?

hi, how do I know on which platform is running my server: Unix or Windows server ? I have only access to ftp, is there any php code to know it ? thanks ...

unistd.h read() function: How to read a file line by line?

What I need to do is use the read function from unistd.h to read a file line by line. I have this at the moment: n = read(fd, str, size); However, this reads to the end of the file, or up to size number of bytes. Is there a way that I can make it read one line at a time, stopping at a newline? The lines are all of variable length. ...

How can I benchmark TCP and UDP using C?

I want to measure message latency and throughput for both TCP and UDP using C sockets. I am writing a client.c and server.c (Question 1: Do I have to?) that run on different servers to accomplish this. I have to take several measurements using different packet sizes and multiple trials and plot my results. For message latency: Send a pa...

How to match any whitespace in body of mail in procmail?

I tried to use such rule: :0 B * Something[[:space:]]+whatever but it doesn't work. When I change [[:space:]] to literal space character: :0 B * Something +whatever it works. It also works in case of: :0 B * Something[ ]+whatever I must be doing something wrong, but can't really find it. Any hints? ...

How do I determine the version of a library in Unix without 'strings' or 'what'

I have a copy of the expat XML processing library on an embedded system running busybox 0.61. I need to find out the version of the library, but I don't have the 'strings' or 'what' applications on the image, nor can I recompile the image. These busybox images that I'm forced to use a grossly impaired. Is there any way for me to find ...

How does one determine console character width from ruby program?

I want to print columnar output from a ruby program, but in order to take full advantage of the available screen space, I need to determine the character width of the terminal the program is running in. How does one do this? ...

a.out replaced by ELF file format ?

I have a few questions: Why was a.out replaced by ELF? What were the major flaws in the a.out format that led to the raise of ELF file format? Earlier core dumps were based on a.out, but now they are based on ELF. What are the various advantages provided by ELF? ...

Interacting with a remote server over network

I need to connect to a remote server whose remote name and PORT number is specified to me. This I need to do over Unix sockets. After connecting with it, I will need to receive the messages the server sends and then send it data as it instructs me to do. I know the steps to make this client program but i'm lost as to the exact things I n...

Running Python With STDIN From Bash

I have a bash code (Mybash1.sh) where the result I need to pass to another bash code (Mybash2.sh) that contain Python Here are the codes. Mybash1.sh #! /bin/bash # Mybash1.sh cut -f1,3 input_file.txt | sort | ./Mybash2.sh Mybash2.sh is this: #! /bin/bash #Mybash2.sh python mycode.py foo.txt <("$@") > output.txt # do something for...

Universal construct for STDIN and Fileinput in Python Code

I want my code to be able to accept input from a file AND stdin. What's the construct to do it? I mean a unifying construct that implies file1 = sys.stdin and file1 = fileinput.input(sys.argv[1]) ...