Tagged Questions
46
votes
11answers
11k views
How do I daemonize an arbitrary script in unix?
I'd like a daemonizer that can turn an arbitrary, generic script or command into a daemon.
There are two common cases I'd like to deal with:
I have a script that should run forever. If it ever ...
17
votes
16answers
14k views
How can I delete a newline if it is the last character in a file?
I have some files that I'd like to delete the last newline if it is the last character in a file. 'od -c' shows me that the command I run does write the file with a trailing new line:
0013600 n ...
8
votes
9answers
2k views
How can I delete all /* */ comments from a C source file?
I have a C file which I copied from somewhere else, but it has a lot of comments like below:
int matrix[20];
/* generate data */
for (index = 0 ;index < 20; index++)
matrix[index] = index + 1;
/* ...
5
votes
5answers
601 views
a program to monitor a directory on Linux
There is a directory where a buddy adds new builds of a product.
The listing looks like this
$ ls path-to-dir/
01
02
03
04
$
where the numbers listed are not files but names of directories ...
3
votes
4answers
462 views
File Manipulation: Scripting Question
I have a script which connects to database and gets all records which statisfy the query. These record results are files present on a server, so now I have a text file which has all file names in it.
...
3
votes
3answers
1k views
How can I print the lines in STDIN in random order in Perl?
I want to do the inverse of sort(1) : randomize every line of stdin to stdout in Perl.
9
votes
4answers
2k views
How to get parameters from config file in R script
Is there a way to read parameters from a file in an R script?
I want to create a config file that has
db_host=xxxx
db_name=xxxx
db_user=xxxx
db_pass=xxxx
and then use it in the R script to create ...
6
votes
5answers
9k views
Running job in the background from Perl WITHOUT waiting for return
The Disclaimer
First of all, I know this question (or close variations) have been asked a thousand times. I really spent a few hours looking in the obvious and the not-so-obvious places, but there ...
3
votes
3answers
1k views
Why does Perl's glob return undef for every other call?
I'm not necessarily looking for a better way to do this, rather an explanations of the output would greatly be appreciated. Recently, a senior programmer asked me why his code worked but only for one ...
8
votes
3answers
2k views
ack-grep: chars escaping
My goal is to find all "<?=" occurrences with ack. How can I do that?
ack "<?="
Doesn't work. Please tell me how can I fix escaping here?
4
votes
5answers
7k views
How to export shell variable within perl script
I have a shell script, with a list of shell variables, which is executed before entering a programming environment.
I want to use a perl script to enter the programming environment:
...
3
votes
4answers
1k views
Why do du and Perl's -s give different values for the file size?
Updated According to comments:
I have outlog.txt file which contains multiple filenames, e.g: 2345_535_Dell&HP_3PAR_DEAL.txt, similarly there are many filename but not the actual folder where the ...
3
votes
2answers
1k views
Is there a Perl module that works similarly to the Unix “which” command?
I was on Perlmonks and found this great listing:
http://www.perlmonks.org/?node_id=627015
But it was missing "which", the function that searches for an executable in all the directories in your ...
3
votes
3answers
5k views
How can I return a value from a Perl program to a Korn-shell script?
I want to do this in a shell script:
#!/usr/bin/ksh
PERL_PATH=/usr/local/bin/perl
RET1=$(${PERL_PATH} missing_months_wrap.pl)
echo $RET1
How do i do it?
calling the perl script as above is ...
1
vote
2answers
295 views
Transpose using AWK or Perl
Hi I would like to use AWK or Perl to get an output file in the format below. My input file is a space separated text file. This is similar to an earlier question of mine, but in this case the input ...