bash

How to count number of unique values of a field in a tab-delimited text file?

I have a text file with a large amount of data which is tab delimited. I want to have a look at the data such that I can see the unique values in a column. For example, Red Ball 1 Sold Blue Bat 5 OnSale ............... So, its like the first column has colors, so I want to know how many different unique values are there in th...

emulating bash 'source' in python

I have a script that looks something like this: export foo=/tmp/foo export bar=/tmp/bar Every time I build I run 'source init_env' (where init_env is the above script) to set up some variables To accomplish the same in python I had this code running reg = re.compile('export (?P<name>\w+)(\=(...

What do ampersand in arithmetic evaluation and numbers with x's mean in Bash?

I'm curious about what exactly the following comparison does, in as much detail as possible, especially relating to the 0x2 and the & characters and what exactly they do, if [ $((${nValid} & 0x1)) -eq 1 ]; then #...snip... fi if [ $((${nValid} & 0x2)) -eq 2 ]; then #...snip... fi ...

How can I have term.el (ansi-term) track directories if using anyhting other than bash.

When using eshell or ansi-term and bash emacs changes the default-directory variable depending on what directory you are in. So if I move to /home/user/code/project and then use ido-find-file to open a file it starts ido with the CWD. If I use ksh (my normal shell) or zsh (tried for testing) it doesnt work. Is there a setting or is this...

What's the meaning of this sed command? sed 's%^.*/%%'

I saw a bash command sed 's%^.*/%%' Usually the common syntax for sed is sed 's/pattern/str/g', but in this one it used s%^.* for the s part in the 's/pattern/str/g'. My questions: What does s%^.* mean? What's meaning of %% in the second part of sed 's%^.*/%%'? ...

Trying to set up bash command

I was trying to set up a bash command in Terminal on a Mac. The scripts run correctly when I execute them directly. I set up symlinks in /usr/local/bin/ to the current location of the scripts. When I try to run it off the symlink, it doesn't work. I don't believe the issue is the $PATH, because pip, git, ipython all exist in this loc...

Sorting in bash

I have been trying to get the unique values in each column of a tab delimited file in bash. So, I used the following command. cut -f <column_number> <filename> | sort | uniq -c It works fine and I can get the unique values in a column and its count like 105 Linux 55 MacOS 500 Windows What I want to do is instead of sorting by th...

Find and kill a process in one line using bash and regex.

I often need to kill a process during programming. The way I do it now is: [~]$ ps aux | grep 'python csp_build.py' user 5124 1.0 0.3 214588 13852 pts/4 Sl+ 11:19 0:00 python csp_build.py user 5373 0.0 0.0 8096 960 pts/6 S+ 11:20 0:00 grep python csp_build.py [~]$ kill 5124 How can I extract the process id ...

Bash - Hiding command (preventing from bad manipulations)

Hello, I was wondering if they was a way to prevent some commands from being executed in order to prevent from bad manipulation sometimes (for exemple you execute "rm *.py" when you wanted to execute "rm *.pyc" or something like that). People will say that it's the user's responsability to check his inputs and it's right but I would li...

Propositional parameters

Hi everyone, below is an extract from a shell script i am tring to make, it is supposed to allow a user to supply files they want to view and the script prints the first lines of the each file and asks if they want to delete them. i have marked where the errors are, i know i am using the $ improperly. any help would be appreciated t...

Split big compressed log files into compressed chunks of X lines while doing inline compression

My situation is the following: a big (10GB) compressed file containing some files (~60) with a total uncompressed size of 150GB. I would like to be able to slice big compressed log files into parts that have a certain number of lines in them (ie: 1 million). I don't want to use split since it involves totally decompressing the original...

Avoid gnome-terminal close after script execution?

I created a bash script that opens several gnome-terminals, connect to classroom computers via ssh and run a script. How can I avoid that the gnome-terminal closes after the script is finished? Here is an example of my code: gnome-terminal -e "ssh root@ cd /tmp && ls" thx for your help ...

Creating bash script of a complex linux command

I have few long commands that I will be using on a day to day basis. So I though it would be better to have a bash script where I could pass arguments, thus saving typing. I guess this is the norm in Linux but I am kind of new to it. Could someone show me how to do it. A example is the following command cut -f <column_number> <filename>...

Can colorized output be captured via shell redirect?

Various bash commands I use -- fancy diffs, build scripts, etc, produce lots of color output. When I redirect this output to a file, and then cat or less the file later, the colorization is gone -- presumably b/c the act of redirecting the output stripped out the color codes that tell the terminal to change colors. Is there a way to ca...

Extract Filenames (without extension) from XML File

I have the following XML output when I grep for "Server": <Server id="1" src="/other/Server/PRX01/PRX01.xml"/> <Server id="2" src="/other/Server/PRX01/PRX02.xml"/> <Server id="3" src="/other/Server/PRX01/PRX03.xml"/> <Server id="4" src="/other/Server/PRX01/PRX04.xml"/> I need to be able to take this output and sed/awk or some other to...

Bash : How to read a directory structure and cache it into an xml document

I need to read a directory structure from the file system and cache it in an xml document. Can someone suggest me on how to do that using bash ? I only need to cache the directories/subdirectories not files under them . The structure is randomly generated , so don't know how many nodes and how much the depth of the tree would be each ...

Bash: How to undo the effect of "set -e" which makes bash exit immediately if any command fails

After enter set -e in an interactive bash, bash will exit immediately if any command exits with non-zero. How can I undo this effect? Thanks. ...

Global function inside in Bash?

I want to define a constant inside a function that could be used outside the function's scope. function section { variable = "Hello" } echo variable Is this possible? ...

Remote backup solution for openSuSE

I'm looking for some backup solution. My request is pretty simple: Source - FTP credentials (ftp://user:[email protected]/dir1/dir2) Destination on local HDD (/var/backup/server-tld) Possibility of packing to archive (tar.gz/zip) Plan this "script" as a cron job with defined period (e.g. once a day) I know, that all this can be done us...

Accesssing bash completions for specific commands programmatically

I'm trying to write a small command launcher application, and would like to use bash's tab completions in my own completion system. I've been able to get a list of completions for general commands using compgen -abck. However, I would also like to get completions for specific commands: for instance, the input git p should display complet...