bash

Wrap Field in a Line with Variable Number of Separators

Hello all, I have a file that uses the pipe character as a separator since I assumed that most of my clients wouldn't use the pipe character in their data. Apparently I was wrong, but I compensated for this by specifying that any fields using the pipe character need to be wrapped in double quotes. Unfortunately, they haven't done this, ...

bash stdout followed by prompt on same line

In bash, some commands put their stdout BEFORE the command prompt and on the SAME line. For example: $ printf message message$ $ gettext -d gtk20 File Fichier$ I want the stdout on a dedicated line with the command prompt on the NEXT line. I could precede with 'echo' and wrap in back ticks like this, but I wonder if there is a bette...

Copy a section into a new file

I have a text file, !--- Marker one --! aaaa bbbb cccc dddd !--- Marker two --! eeee ffff !--- Marker three --! gggg hhhh iiii And I need to copy from Marker two (till the end of Marker two) into a new file, using Bash. !--- Marker two --! eeee ffff Becomes a separate file. ...

Filtering Rows Based On Number of Columns with AWK

I have lines of data that contain single column and two columns. What I want to do is to extract lines that contain only 2 columns. 0333 foo bar 23243 qux yielding only: 0333 foo 23243 qux Note that they are tab separated, even for lines with only one column you have tab at the beginning. What's the way to do it? I tried this...

SSH doesnt exit from command line..

Hi, I ssh to another server and run a shell script like this nohup ./script.sh 1>/dev/null 2>&1 & Then type exit to exit from the server. However it just hangs. The server is Solaris. How can I exit properly without hanging?? Thanks. ...

How do you find the factorial of a number in a Bash script?

In shell scripting how to find factorial of a number? ...

run/invoke windows batch script from sh or bash script

Hello, I have a sh/bash script that needs to call a batch file with parameters (parameters are file names and are given in DOS/Windows format). Basically I have: script.sh #!/bin/sh declare var1=$1 declare var2=$2 dosomething var1 var2 ... <invoke batch script> var1 var2 ... dosomethingelse I'm using GNU bash, version 3.1.0(3)-releas...

Weird behaviour of string variables in bash script...Please help!

Hi all, I'm going nuts with this...let me explain... I have a very simple Bash script with a function in it that receives 3 arguments. Those arguments are all strings. Everything was working fine 'til I had to pass a string with whitespaces to the function. I also have some test code to call the function (whose name is substracFromF...

In a shell (bash) How can I execute more than one command in a pipeline?

I'm trying pipe the output of an awk command through more than one command at once in a Bash shell, following my knowledge I'm coming up with this: awk '$13 ~ /type/ {print $15}' filename.txt | (wc -l || sort -u) I want the result of the awk command to be both counted AND sorted, how can I accomplish that? Even with && command it does...

POSIX shell like implementation in Java

Does anybody know of an implementation of POSIX shell like language for scripting things in Java? If this is not available, does anybody know if there is a ANTLR or JavaCC grammar available somewhere which I might have missed? edit: I know that I have Jython, JRuby, Groovy, JavaScript available for scripting, but none of them have ba...

bash: Filtering out directories and extensions from find?

I'm trying to find files modified recently with this find . -mtime 0 Which gives me en/content/file.xml es/file.php en/file.php.swp css/main.css js/main.js But I'd like to filter out the en and es directories but would like to grab anything else. In addition, I'd like to filter out .swp files from the results of those. So I want t...

In Unix / Bash, is "xargs -p" a good way to prompt for confirmation before running any command?

I have asked how to make any command "ask for yes/no before executing" in the question http://stackoverflow.com/questions/3231804/in-bash-how-to-add-are-you-sure-y-n-to-any-command-or-alias It seems like for the command hg push ssh://[email protected]//somepath/morepath I can also do this: echo ssh://[email protected]...

Bash syntax error: "[[: not found"

I'm working with a bash script that is currently working on a server (RHEL4). I'm developing on my laptop with Ubuntu 10.04, but I don't think the platform is causing the problem. Here's what's happening: I have a skeleton script that calls another script that does most of the work. However, it makes calls to getConfig.sh a lot. getConf...

How would you group a number of lines?

Let's say you have the following. 192.168.0.100 192.168.0.100 192.168.0.100 192.168.0.102 192.168.0.102 192.168.0.100 That's considered 3 unique hits. The way to distinguish it is that consecutive identical IPs count as one. How would you loop through the file and count accordingly? ...

How to configure firefox over command line on a linux machine

I use two Internet connections so i want to use bash scripts to automate the task of switching between the two.. the problem is i cant able to configure firefox proxy settings via scripts, so is there a way to do that... does any configuration file exists for firefox so that i can modify over command line.. I have read this entry but th...

how do I find where a executable is present in macosx?

I have a command called youtube-dl .. but dont know where it is installed.. i can run it from shell.. how do i find where it is installed ? which youtube-dl doesnt say anything.. ...

Bash: how to pipe each result of one command to another

Hi All, I want to get the total count of the number of lines from all the files returned by the following command: shell> find . -name *.info All the .info files are nested in sub-directories so I can't simply do: shell> wc -l *.info Am sure this should be in any bash users repertoire, but am stuck! Thanks ...

Writing a Cron Job That Can Access User Data

I'm trying to write a cron job that runs a report, and emails the result to an address defined in my user's ~/.bashrc file. I had this working perfectly on Fedora, but when I switched to Ubuntu, my solution no longer works. The command my cron job currently runs is: . /home/myuser/.bashrc; /home/myuser/bin/runreport If I run that comm...

Rsync bash script and hard linking files.

I am creating a bash script to backup my files with rsync. Backups all come from a single directory. I only want new or modified files to be backed up. Currently, I am telling rsync to backup the dir, and to check the files compared to the last backup. The way I am doing this is THE_TIME=`date "+%Y-%m-%dT%H:%M:%S"` rsync -aP --link...

Retrieve plain text script from compiled bash script

Some time ago, i wrote some bash scripts for my school. I thought it would be very clever to 'protect' them, so i compiled them with shc into a binary file. Some weeks later, i lost the uncompiled scripts and now i have only my binarys left. Is there a way to retrieve the scripts back from the shc generated binarys? I looked into the so...