shell

how to delete a line from file using awk filtered by some string

I have a file delimited by space. I need to write an awk command that receives a host name argument and it should replace the host name if it already defined in the file. It must be a full match not partially - if the file contains this host name: localhost searching for "ho" will fail and it will be added to the end of the file. anothe...

Is there a way to load a profile inside Perl?

Is there a way to load a profile inside Perl? Like in shell files: . ~user/.profile ...

Parsing result of Diff in Shell Script

I want to compare two files and see if they are the same or not in my shell script, my way is: diff_output=`diff ${dest_file} ${source_file}` if [ some_other_condition -o ${diff_output} -o some_other_condition2 ] then .... fi Basically, if they are the same ${diff_output} should contain nothing and the above test would evaluate to tr...

How can a PHP script detect if it has been invoked as a script or from the shell?

I have a PHP script on a webserver. This file is invoked via the shell by another program but it could still be run by the webserver in response to an HTTP request. How can the script determine the way it was invoked? ...

exiting script while running source scriptname over SSH

I have a script with a number of options in it one of the option sets is supposed to change the directory and then exit the script however running over ssh with the source to get it to change in the parent it exits SSH is there another way to do this so that it does not exit? my script is in the /usr/sbin directory. ...

Open Python shell through SSH

I'm using this tool to set up a ssh server on Windows. I'm trying to open the standard Python shell through a remote ssh connection but I simply can't get it to work. If I type 'python' in my ssh command line nothing happens, it just seems to wait for more input. My server machine however, shows a new python process running after I do th...

why is the line #!/bin/ksh is the first line in a shell script

#!/bin/ksh is the first line in a shell script always what is the importance of this line and why is it kept as the first line. ...

How to replace pairs of strings in two files to identical IDs?

[Update2] As it often happens, the scope of the task expanded quite a bit as a understood it better. The obsolete parts are crossed out, and you find the updated explanation below. [/Update2] I have a pair of rather large log files with very similar content, except that some strings are different between the two. A couple of examples: ...

GET command is giving two kinds of ouput,why???

iam using GET command to get the content of a page.When i write the same command on shell prompt it gives correct result but when i use that in PHP file then sometimes its giving correct result but sometimes it gives only half of the content i.e. end-half portion only. Iam using following command in shell script :- GET http://www.abc.c...

Replace text from a MySQL dump using cat (or something else) in shell

I've got a database dump in MySQL where I want to replace ocurrencies of paths that are in the dump as plaintext. In this particular case I'd like to replace: /var/www/ for /home/www/ How could I safely do that using cat or any other shell tool? ...

shell script background

I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.33.2.tar.bz2 tar -xjf linux-2.6.33.2.tar.bz2 fi for i in $(seq 1 500); do touch /tmp/$i.txt done I'm downloading tar file and then decompress i...

Copy one column over another in a delimited file

For instance, I needed to remove column 25 and replace it with a copy of column 22 in a simple csv file with no embedded delimiters. The best I could come up with was the awkward looking: awk -F, '{ for(x=1;x<25;x++){printf("%s,", $x)};printf("%s,",$22);for(x=26;x<59;x++){printf ("%s,", $x)};print $59}' I would expect something like ...

In KDE4, how can I automatically tell which “Desktop” a Konsole terminal is in?

I was looking for this and found a question and answer for KDE3; I figured more people will be interested in the answer for KDE4 as time passes (posting here just so I can also post the answer...) ...

sed/awk or other: one-liner to increment a number by 1 keeping spacing characters

EDIT: I don't know in advance at which "column" my digits are going to be and I'd like to have a one-liner. Apparently sed doesn't do arithmetic, so maybe a one-liner solution based on awk? I've got a string: (notice the spacing) eh oh 37 and I want it to become: eh oh 36 (so I want to keep the spacing) Using awk I don't fi...

pass commands to an running R-Runtime

Hi, is there a way to pass commands (from a shell) to an all ready running R-runtime/R-Gui, without copy&past. So far I only know how to call R via shell with the -f or -e option, but in both cases a new R-Runtime will process the R-Script or R-Command I passed to it. I rather would like to have an open R-Runtime waiting for commands pa...

Storing Shell Output

Hello everybody, I am trying to read the output of a shell command into a string buffer, the reading and adding the values is ok except for the fact that the added values are every second line in the shell output. for example, I have 10 rows od shell output and this code only stores the 1, 3, 5, 7, 9, row . Can anyone point out why i am...

Quote POSIX shell special characters in Python output

There are times that I automagically create small shell scripts from Python, and I want to make sure that the filename arguments do not contain non-escaped special characters. I've rolled my own solution, that I will provide as an answer, but I am almost certain I've seen such a function lost somewhere in the standard library. By “lost” ...

Shell Script - comparing lines of text, deleting matches

Hi all, I've done some searching for this but cannot find what I'm after, specifically. I have two files: "a.txt", "b.txt". Each contains a list of email addresses, separated by newlines. For all lines in "a.txt", I need to check for a match anywhere in "b.txt". If so, the email address in "a.txt" needs to be removed. (Alternativel...

Bourne: if statement testing exit status

What is the difference: if IsServerStarted ; then ... and if [ IsServerStarted -eq 0 ] ; then ... Seems to me that these two statements should be equivalent? Strangely the second statement is always true. ...

Replace delimited block of text in file with the contents of another file

I need to write a simple script to replace a block of text in a configuration file with the contents of another file. Let's assume with have the following simplified files: server.xml <?xml version='1.0' encoding='UTF-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Service name="Catalina"> <Connector port="80" protocol="HTTP/1.1"...