bash

When SSHing into system, is there a way to launch netbeans from command-line like I do VIM?

VIM seems integrated to the terminal. Can I open a remote file from the command-line with netbeans? Does it have shell integration? Any further explanation on this so I can better conceptually understand it would be very appreciated. ...

Java exec() does not return expected result of pipes' connected commands

I'm calling command line programs connected by pipes. All this works on Linux for sure. My method: protected String execCommand(String command) throws IOException { String line = null; if (command.length() > 0) { Process child = Runtime.getRuntime().exec(command); InputStream lsOut = child.getInputStream(); ...

Enabling mouse and paste support in command line vim

I've found these two articles http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl (see 31.13) and http://www.tummy.com/journals/entries/jafo_20060727_145450 But am unfamiliar with basic vim setup. Can anyone help me with a step by step instructions to making mouse usuage in command line mode automatically enabled? (and you will have g...

Best way to modify a file when using pipes?

I often have shell programming tasks where I run into this pattern: cat file | some_script > file This is unsafe - cat may not have read in the entire file before some_script starts writing to it. I don't really want to write the result to a temporary file (its slow, and I don't want the added complication of thinking up a unique new ...

Compare file with variable list AWK

I'm stumbling over myself trying to get a seemingly simple thing accomplished. I have one file, and one newline delimited string list. File: Dat1 Loc1 Dat2 Loc1 Dat3 Loc1 Dat4 Loc2 Dat5 Loc2 My list is something like this: Dat1 Dat2 Dat3 Dat4 What I am trying to do is compare the ...

Using diff and supressing entirely different files

I have two copies of an application source code. One copy is encoded, while the other is not. There are config files scattered through-out the application's directory structure, and this is what I would like to compare. Is there a way to use diff where-by I can ignore the wildly different files (ie: An encrypted file and an unencrypted ...

Bash scripting problem

cat hosts.txt | while read h; do telnet $h; done When I run this, it telnets to first host which denies the connection but then exists instead of looping over the other hosts in the file. Why is it exiting the loop after the first host and how can I fix it? Thanks. ...

How to use 'patch' command with the standard output?

I'm trying to catch an output of bash patch command on a standard output, but I receive a "patch -o- some/file patch: can't output patches to standard output" warning. Tell me please, how I can make it properly? Maybe I'm stupid and the solution is really simple? ...

pipe many outputs to same file at the same time?

Say i have a bash script: #!/bin/bash php ./listen.php 3001 3003 26 & php ./listen.php 3002 3004 120 & can i pipe all of them to same output log file at the same time without conflict? example: #!/bin/bash php ./listen.php 3001 3003 26 >/tmp/log 2>&1 & php ./listen.php 3002 3004 120 >/tmp/log 2>&1 & ...

Exclude $0 when echoing the arguments of a command in a loop (BASH)?

I'm trying to use a for loop to get the filenames of files that end in .cpp. Code: for cppfile in ls *.cpp ; do echo $cppfile done I plan on doing more than just echoing the argument, but as it stands now, it works fine except that I'l get the command as the first arguement. Is there an easy way to avoid this, or will I have to do ...

Need a good book to help me learn bash, solaris and unix in general.

Just started a new coop workterm and using a solaris machine with bash as my shell. Know basic commands in bash: ls, pwd, find, cd, mkdir, rm, grep ... That is basically all I need to do my job (working in java with intellij), but would like to be able to use my machine better. Can anybody recommend a book for me? Hopping for some l...

Tell if a user has SUed in a shell script?

I have a script which executes a git-pull when I log in. The problem is, if I su to a different user and preserve my environment with an su -lp, the script gets run again and usually gets messed up for various reasons because I'm the wrong user. Is there a way to determine in a shell script whether or not I'm currently SUing? I'm looking...

Replace only within a XML tag; exporting from Referencer .reflib to bibtex format with filenames intact and URL-encoding removed, with a bash command

I have many references in Referencer. I'm trying to include filenames in my bibtex file when exporting from Referencer. Since the software doesn't do this by default I'm trying to use a sed command to include the filename as a bibtex information in the XML file before I export and thus include the filename. Input <doc> <filename>...

if statement error bash

Please help me to find problem t1=$(sort -k 2,2 f.txt|head -1|cut -d" " -f3) while read x do t2=$(echo $x|cut -d" " -f2) if [ $t2 -ge $t1 ] ; then p=$(echo $x|cut -d" " -f1) echo -n $p " " fi done <f.txt f.txt F1 13 G 13 H 0 I am geeting following error -sbash: [: 13: unary operator expected -sbash: [: 13: unary operator ...

Grepping complex strings in variables.

All - I am trying to grep for a small string in a much larger string. Both strings are being stored as variables. This code is an example - #!/bin/bash long_str=$(man man) shrt_str="guide" if grep -q $shrt_str $long_str ; then echo "Found it!" fi I don't think variable expansion is working the way I expect it to. I have ...

replace a particular value in a string of key - values

I have a large string which is a collection of key (space)+ value, i.e key followed by one or more space and then value. Now i need to change the value of a particular key using sed, awk, grep etc. in unix environment. eg. of string: -Key1 Value1 -Key2 Value2 -Key3 Value3 I need a new string that is same as above only Va...

How to loop over directories in Linux?

I an writing a script in Linux and need to go over all subdirectories names in a given directory. How can i loop these directories (and skip regular files). For example, the given directory is /tmp/ and has the following subdirectories: /tmp/A, /tmp/B, /tmp/C I want to retrieve A,B,C. ...

How to find duplicate files with same name but in different case that exist in same directory in Linux?

How can I return a list of files that are named duplicates i.e. have same name but in different case that exist in the same directory? I don't care about the contents of the files. I just need to know the location and name of any files that have a duplicate of the same name. Example duplicates: /www/images/taxi.jpg /www/images/Taxi.jp...

How to get the name of the current git branch into a variable in a shell script?

I am new to shell scripting and can't figure this out. If you are unfamiliar, the command git branch returns something like * develop master , where the asterisk marks the currently checked out branch. When I run the following in the terminal: git branch | grep "*" I get: * develop as expected. However, when I run test=$(gi...

What file explorer can I use in Cygwin with UNIX like paths?

I'm fed up with using Windows Explorer as my file browser as I use Cygwin bash as my primary command line environment. Windows Explorer shows the full path in the address bar. Usually, I copy that, pasting it to the cygwin command prompt as in cygpath "" I then copy paste the output of cygpath so I can cd to it. I've also set up c...