Hello. I have a tab delimited file with 5 columns and need to retrieve a count of just the number of unique lines from column 2. I would normally do this with Perl/Python but I am forced to use the shell for this one.
I have successfully in the past used *nix uniq function piped to wc but it looks like I am going to have to use awk in h...
Hi,
I'm using the following to generate a random password in a shell script:
DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8)
When i run this in a file on its own like this:
#!/bin/sh
DBPASS=</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 8)
echo $DBPASS
A password is echoed...
I have a manifest file which is just a list of newline separated filenames. How can I remove all files that are not named in the manifest from a folder?
I've tried to build a find ./ ! -name "filename" command dynamically:
command="find ./ ! -name \"MANIFEST\" "
for line in `cat MANIFEST`; do
command=${command}"! -name \"${line}\" ...
I'm looking for a way to find what I know will be a unique file, and then change into the directory containing that file. Something along the lines of:
find . -name 'Subscription.java' | xargs cd
Or:
find . -name 'Subscription.java' -exec cd {} \;
I know this won't work because it's both trying to cd supplying the entire absolute path, w...
I've noticed that some programs have their own tab-completion.
For example, git:
git checkout
allows for tab completion of branch names.
How is this accomplished?
...
i have never used PHP with CLI, but i have seen scripts run with php code.
i was wondering, why should we use bash, when php is so popular and is able to run in CLI.
what are the pros and cons with each one?
should i use php for all CLI scripting in the future?
...
i have text such as
http://pastebin.com/H8zTbG54
we can say this text is set of rules splitted by "OR" at the end of lines
i need to put set of lines(rules) into buckets (bash array members) but i have character limit for each array member which is 1024
so each array member should contain set of rules but character count for each ...
I have a text file test.txt with the following content:
text1
text2
And I want to assign the content of the file to a UNIX variable but when I do this:
testvar=$(cat test.txt)
echo $testvar the reult is:
text1 text2
instead of
text1
text2
Can someone suggest me a solution for this?
...
How do I write a batch process on the Mac for pdf2swf, I want to convert all pdfs in a folder into swf. But pdf2swf doesn't have a option to convert a folder of pdfs to swfs, you have to do it one at a time. I'm not sure how if I should use a Apple script or a Shell script, either one I'm not sure how to get or assign a file name variabl...
Hi all,
I've got a GUI C++ program that takes a shell command from the user, calls forkpty() and execvp() to execute that command in a child process, while the parent (GUI) process reads the child process's stdout/stderr output and displays it in the GUI.
This all works nicely (under Linux and MacOS/X). For example, if the user enters...
I'm looking for a way to copy all non-system users from one PC to another. I can get the group and passwd files copied over using this
awk -F":" ' $3 > 499 ' etc/passwd >> /etc/passwd
awk -F":" ' $3 > 499 ' etc/group >> /etc/group
But, how would I go about getting the shadow file copied over since it does not store the UID? Assume tha...
How can i get a particular line in a 3 gig text file. The lines are delimited by \n. And i need to be able to get any line on demand.
How can this be done? Only one line need be returned.
Update: If it matters, all the lines have the same length
...
Hi,
What exactly are the uses of '-' in bash? I know they can be used for
1. cd - # to take you to the old 'present working directory'
2. some stream generating command | vim - # somehow vim gets the text.
My question is what exactly is - in bash? In what other contexts can I use it?
Regards
Arun
...
This is, perhaps, a silly question, but it's something that I've wondered about: is it possible to, say, define a Ruby/Python/Perl/etc. function in some file and then source it in Bash (to make it available anywhere in the current shell)?
At the moment, I "source" scripts/functions in other languages by creating a bash alias that execut...
My question is very similar to this one except that my background process was started from a script. I could be doing something wrong but when I try this simple example:
#!/bin/bash
set -mb # enable job control and notification
sleep 5 &
I never receive notification when the sleep background command finishes. However, if I execute t...
I have JPG files numbered 3006-3057 that I would like to reverse number. I would be content renaming them by adding a backwards number count to the beginning of the name: img_3006.jpg > 99_img_3006.jpg and img_3057.jpg > 48_img_3057.jpg.
...
I'm writing a bash script to sync my iTunes music directory to a directory on a removable hard drive. The script works fine when there is absolutely nothing in the folder on the external hard drive. Once all files have been copied to the external drive, then the script begins to act strange. Even though i just sync'd everything over, it ...
Hello,
How would I pass a Python variable to the Bash shell? It should work like this:
foo="./RetVar.py 42"
Replace the double-quotes with `s
I have tried printing and sys.exiting the result, but to no avail. How would I accomplish my goal?
...
Hi
I want to write a script that will:
1- locate folder "store" on a *nix filesystem
2- move into that folder
3- print list of contents with last modification date
4- calculate sub-folders size
This folder's absolute path changes from server to server, but the folder name remains the same always.
There is a config file that contai...
I have a large directory tree of files, and am using the following script to list and replace a searched-for name with a specific file. Problem is, I don't know how to write the createList() for-loop correctly to account for whitespace in a directory name. If all directories don't have spaces, it works fine.
The output is a list of file...