This was an interview question, nevertheless still a programming question.
I have a unix file with two columns name and score. I need to display count of all the scores.
like
jhon 100
dan 200
rob 100
mike 100
the output should be
100 3
200 1
You only need to use built in unix utility to solve it, so i am assuming using shell scrip...
I need to execute a unix command with different args in a loop. Now I wonder if I should use execvp(), passing in the cmd and the args, or use system, building a string consisting of cmd + args?
...
Hi,
I want to excecute unix command from remote PC using XManager 2, and I try to create this script on unix box as below
!/bin/sh
#
/usr/dt/bin/dtterm -ls -display 192.19.250.100:0.0 <<- XEND
prtdiag
XEND
and I executed that script from XManager.
the terminal windows can be open but this script not execute the command,
any su...
Basically,expected output of is that it catches KeyboardInterrupt 5 times and exits the 6th time.(If 1st line of handler() is un-commented)
Now, if i comment that line too, then
also the behavior of program doesnt
change even though I am using
unreliable API.
As I have used signal() function, this is unreliable bcos after the...
I have a QApplication that, depending on command line parameters, sometimes doesn't actually has a GUI window, but just runs without GUI. In this case, I want to shut it down gracefully if CTRL-C was hit. Basically my code looks like this:
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
... // parse command ...
I need to write a shell script that pick all the files (not directories) in /exp/files directory. For each file inside the directory I want to find whether the last line of file is received . The last line in the file is a trailer record. Also the third field in the last line is the number of data records count i.e 2315 (Total Numbe...
Hi,
I'm told to write a program in 'C' to print the contents of the 'super block'. Can anybody tell me how to read the contents of the super block. Which system call can be used to do so?
Thanks.
...
Pasted a piece of code from the shell script transfer.sh
if [[ ${ld} -eq ${eld} ]] ; then
mv "$file1" "$FILESNEW/."
if [ $? -ne 0 ]; then
echo "Move Command Failed-File ${fspec}"
fi
echo "File ${fspec} Sucessfully Moved to ready directory "
else
e...
I have a file folders.txt
one
two
three
four
...
that has a list of folder names. [one, two, three and four are names of folders].
Each of these folders has a number of files of different types (different extensions). I want a list of all the files in all the folders of one particular extension, say .txt.
How should my shell script ...
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?
...
After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the directories in the path without resorting to manually parsing my directory string and individu...
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?
...
I read about standard streams. My understanding is old fashioned programs that don't have GUI need some kind of user interface, too. So Operating System provide each of them with a console window, and the console window's out/input/err stream was mapped to the program's standard input/output/error stream. And thus these programs are call...
Since I am conversant in Ruby, I am about to script a few things on OSX using it. But then I thought, perhaps I am missing the boat. I know a lot of reasons to prefer Ruby over Bash (or whatever sh-compatible command language interpreter), but I don't know any reasons not to. What is the upside of programming the shell directly?
I inten...
I've been reading the man page for read(2) and according to the man page, the return value of read(2) is -1 on error, 0 on EOF, and > 0 for the number of bytes read.
How do I tell when the write(2) on the client is finished ?
I ask because I'm writing a server and a client to test it, but when I read(2) the first time and loop arou...
Hello guys,
I'm looking to find a way how to identify a non responding (not zombie) process programatically. I find some information to check TH_STATE_UNINTERRUPTIBLE status but there was some discussion that it's not the right way. Any ideas?
...
Hello,
I'm working on refactoring a suite of old utilities and creating a new server that's going to use common code from all of them to unify their functionality and allow external access by remote clients. For each utility, I'm taking the code I need for the server and refactoring it out into a shared library so that the utility and ...
Hypothetical situation. I have a command line program in *nix (linux, BSD, etc.). It was written so that you pass it a text file as an argument
$ program file.txt
Run the program, it looks at the text in file.txt.
Is it possible to "trick" this program into accepting input from a file stream rather than reading a file via disk? ...
I am trying to ftp a file from unix to as400 and executing iseries command in the script.
ftp is working fine,I am getting an error in jobd command as
HOST=KCBNSXDD.svr.us.bank.net
USER=test
PASS=1234 #This is the password for the FTP user.
ftp -env $HOST << EOF
# Call 2. Here the login credentials are suppli...
I have both matrices containing only ones and each array has 500 rows and columns. So, the resulting matrix should be a matrix of all elements having value 500. But, I am getting res_mat[0][0]=5000. Even other elements are also 5000. Why?
#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
#include<stdlib.h>
#define ROWS 500
#defi...