shell

How to run shell script on remote machine from Java?

I'm creating a test which will perform some stress testing of the app which talks to a Postgres database. In order to make it replicable I'd like to recreate the database on every run. Startup method decorated with org.junit.Before annotation will drop the database (if it exists) and restore it from a dump file. Doing this form shell/com...

How to compare two files in shell script?

Here is my scenario. I have two files which are having records with each record's 3-25 characters is an identifier. Based on this I need to compare both of them and update the old file with the new file data if their identifiers match. Identifiers start with 01. Please look at the script below. This is giving some error as "argument expe...

How to Replace a line in the same file by SED in Unix Shell scripting?

Hi In Reference to this question After getting the line identifier matching in first and second file I need to replace the line in first file with the line of second file.For that I am using SED as below. But Sed only replaces that line in a new file. How can I achieve the updation in same file without temporary file.(Because those are v...

Script for changing the sequence number on a file name

I am writing a shell script and I am stuck. The requirement is: I will receive files which have a sequence number on them like xyz0001abcd.DAT. I create a copy of that file, keeping the sequence number, as abcd000001gfh.DAT. The original filename uses four digits (up to 9999), and the copied one uses six (up to 999999). I am stuck when...

grep utility in shell script

I'm trying to overcome a limitation on our file structure. I want to grep a whole series of files in a known location. If I do a standard grep from command line (grep -i searchpattern known_dir/s*.sql) I get the following error: ksh: /usr/bin/grep: 0403-027 The parameter list is too long. so I have a little for loop that looks l...

Shell script for getting the sequence and changing it?

I have a command like echo "abcd0001gfh.DAT" | sed 's/^[^0-9]*\(....\).*$/\1/' | awk '{ print "00"$0 }' This will give me an output of 000001. But I want to run this in a loop where I receive the file name from 0001-9999 and again it becomes 0001. So my output should like below abcd0001gfh.DAT 000001 abcd0002gfh.DAT 000002 . . . a...

rename a file in c

I was just wondering how could i rename a file on unix platform using a c program without using the standard rename function.any ideas? rename a file in c ...

Mac OS X Terminal Colors

I'm new to Mac having just got one after working with Ubuntu Linux for some time. Among the many things I'm trying to figure out is absence of colors in my the terminal window - like the ones that are shown (on linux) when you run 'ls -la' or 'git status'... I just can't figure out how to activate them in the actual shell. ...

catching error codes in a shell pipe

I currently have a script that does something like ./a | ./b | ./c I want to modify it so that if any of a, b or c exit with an error code I print an error message and stop instead of piping bad output forward. What would be the simplest/cleanest way to do so? ...

Optimized code on Unix?

What is the best and easiest method to debug optimized code on Unix which is written in C? Sometimes we also don't have the code for building an unoptimized library. ...

Grab SQL being executed in a shell script

Given a shell script containing a bunch of SQL statements, is there an option to redirect just the SQL statements to stdout/file? The structure of the script is something like this: ... for i in *list* do isql *credentials etc* <<EOF > a.out select *about 100 cols* from $i + "_TAB" go EOF done ... Query has been...

home, end, delete, pageup, pagedown with ksh

Hello. I want to use home, end, delete, pageup, pagedown with ksh. My TERM is xterm-color. These keys works fine with tcsh and zsh, but not with ksh (print a tilde ~) I found this: bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward bind '^[[1'=prefix-2 bind '^[[1~'=beginning-of-line bind '^[[4'=prefix-2 bind '^[[4~'=end-of-line ...

Switch from file contents to STDIN in piped command? (Linux Shell)

I have a program (that I did not write) which is not designed to read in commands from a file. Entering commands on STDIN is pretty tedious, so I'd like to be able to automate it by writing the commands in a file for re-use. Trouble is, if the program hits EOF, it loops infinitely trying to read in the next command dropping an endless to...

shell matching a pattern using a case-statement which is stored inside a variable

I am trying to match a pattern with a case-statement where the pattern is stored inside a variable. Here is a minimal example: PATTERN="foo|bar|baz|bla" case "foo" in ${PATTERN}) printf "matched\n" ;; *) printf "no match\n" ;; esac Unfortunately the "|" seems to be escaped (interestingly "*" or...

detecting windows shell changes

There is a whole host of components that I am trying out to better understand how to detect when a file or folder has changed. I want to write a delphi application to also do this but delphi Unicode(Tiburon) doesn't seem to ship with any component that can accomplish this. At least not anymore. I found a curious component on the palette...

Is there an Eclipse plugin to run system shell in the Console?

Do you know of any Eclipse plugin to run a system shell in the included console? It would be awesome. Dolphin, KDE's file navigator, has this feature, you can press F4 and a console shows located on the directory you are standing. It would be awesome to have a similar feature on Eclipse, with the shell located on the directory of the pr...

connect to a DB inside awk script

Hi In a shell script we can connect to a Database using sqlplus on unix. can i perform the same thing inside an awk script? i need to access the output of a select query inside an awk script.is that possible? ...

How to count differences between two files on linux?

Hi all, I need to work with large files and must find differences between two. And I don't need the different bits, but the number of differences. For the differ rows I come up with diff --suppress-common-lines --speed-large-files -y File1 File2 | wc -l And it works, but is there a better way to do it? And how to count the exact ...

pipe the output of a command into less or into cat depending on length

First, let me state that this is a programming question (and thus does not belong on superuser et. al.) because I'm talking shell programming. This could almost be a golf question, but I do not have an answer to begin with, so any help would be appreciated :-) So, the story is: I like to pipe stuff into less with the --quit-if-one-scree...

Capistrano :shell example

Hello experts. I'm currently using Capistrano to deploy my web application which works like a charm. In my new project I must execute a command from sudo /bin/bash shell. Is it possible for Capistrano to login to the machine as user X, run sudo /bin/bash, enter the password and then execute a command in the sudo shell? If yes, could yo...