Given: One big text-data file (e.g. CSV format) with a 'special' first line (e.g., field names).
Wanted: An equivalent of the coreutils split -l command, but with the additional requirement that the header line from the original file appear at the beginning of each of the resulting pieces.
I am guessing some concoction of split and hea...
What is the difference between using an environment variable, like PATH, as $PATH or ${PATH}?
...
I have an awk script that I have defined thusly:
#!/usr/bin/env awk
BEGIN { if (!len) len = 1; end = start + len }
{ for (i = start; i < end; i++) { print $1 } }
I have saved it as columns and chmod +x'd it. I want invoke it so that start and end are defined as it traverses over a file. I was thinking this should work:
cat some_file ...
I have the following:
mysqldump -u xxxx
-h localhost
--password=xxxxx databasename |
ssh [email protected] "dd of=httpdocs/backup`date +'%Y-%m-%d-%H-%M-%S'`.sql"
...which SSH's a mysqldump to a remote machine.
I need to compress the mysqldump before it is SSH'd as the dump is 500mb and its e...
"awk: Function systime is not defined."
but systime is a built in command
...
I need to allow several applications to append to a system variable ($PYTHONPATH in this case). I'm thinking of designating a directory where each app can add a module (e.g. .bash_profile_modulename). Tried something like this in ~/.bash_profile:
find /home/mike/ -name ".bash_profile_*" | while read FILE; do
source "$FILE"
done;
but i...
Is there a shell equivalent of PHP's preg_match?
I'm trying to extract the database name from this string in a shell script.
define('DB_NAME', 'somedb');
Using preg_match in PHP I could just do something like this.
preg_match('define(\'DB_NAME\','(.*)'\'\)',$matches);
echo $matches[1];
How can I accomplish the same thing in a she...
Hi I want to delete a line from a file which matches particular pattern
the code I am using is
BEGIN {
FS = "!";
stopDate = "date +%Y%m%d%H%M%S";
deletedLineCtr = 0; #diagnostics counter, unused at this time
}
{
if( $7 < stopDate )
{
deletedLineCtr++;
}
else
...
I have two variables: X and Y.
The value of X will be a date given in the format mmddyy
and I want to calculate the date preceeding that date and have it be returned in in the format yyyymmdd.
Let me give you an example. When X="091509" (mmddyy format) Y should be "20090914" (yyyymmdd format)
...
# find /home/shantanu -name 'my_stops*' | xargs ls -lt | head -2
The command mentioned above will list the latest 2 files having my_stops in it's name. I want to keep these 2 files. But I want to delete all other files starting with "my_stops" from the current directory.
...
I'm trying to figure out the best way to find the number of files in a particular directory when there are a very large number of files ( > 100,000).
When there are that many files, performing "ls | wc -l" takes quite a long time to execute. I believe this is because it's returning the names of all the files. I'm trying to take up as ...
Under windows, when I need to perform a basic calculations, I use a built-in calculator. Now I would like to find out what is the common way if you only have a shell.
Thanks
...
ls > ls.out
this will include ls.out in the list too.
My understanding is: > (shell output redirection operator is creating a file first (to take the STDOUT) if it is not already existing and then ls command is coming to play and it is including the just created ls.out file in the output.
Is this correct? If not, can you please elab...
I'm porting a Linux tool-set that makes frequent use of shell functions to provide certain functionality. These functions are automatically sourced when you start a new shell and include things like changing the working directory, which is nigh impossible with stand-alone programs because child processes can't change their parent's envir...
I am wrapping up an office application (VBA) that makes a call to a C# console application to perform some of the heavy lifting for the application (large simulation program). I would like to be able to have the VBA application wait for the console application to complete as well as retreive the exit code from the console application. ...
I want to remove all lines where all the second column 05408736032 are same
0009300|05408736032|89|01|001|0|0|0|1|NNNNNNYNNNNNNNNN|asdf| 0009367|05408736032|89|01|001|0|0|0|1|NNNNNNYNNNNNNNNN|adff|
these lines are not consecutive. Its fine to remove all the lines . I dont have to keep one of them around.
Sorry my unix fu is really w...
So I have .csh script generate.csh
I want to call another .csh script from within it.
I tried
./shell_gen.csh test1 test2.prt
But it runs shell_gen.csh but without command line arguments.
Anyone?
Thanks
generate.csh
#!/bin/csh
./shell_gen.csh test1 test2.prt
shell_gen.csh
#!/bin/csh
set source = output
########################...
I want to set up some alias and would like to keep them so I don't have to reset them every time I have a new Terminal open. How can I do that? Would it require modifying hidden files?
EDIT: I'm using Mac, I found a bashrc under /etc, is it the one?
...
I was wondering if there is a way to comment out a set of lines in a shell script.
How could I do that? We can use /* */ in other programming languages.
This is most useful when I am converting/using/modifying another script
and I want to keep the original lines instead of deleting.
It seems a cumbersome job to find and prefix # for al...
Is there way to delete duplicate lines in a file in Unix?
I can to it with sort -u and uniq commands. but I want to use sed or awk.
Is that possible?
...