shell

how do you parse comma-separated-values (csv) with awk?

I am trying to write an awk script to convert a CSV formatted spreadsheet into XML for Bugzilla bugs. The format of the input CSV is as follows (created from an XLS spreadsheet and saved as CSV): tag_1,tag_2,...,tag_N value1_1,value1_2,...,value1_N value2_1,value2_2,...,value2_N valueM_1,valueM_2,...,valueM_N The header column represe...

How to rollover the standard output from bash?

I have a script running in the background that prints some output. I redirected the standard output to a file for log purposes. However I don't want this file to grow forever, what would be a good way to do rollover without coding the logic myself? (Either rollover based on date or file size). ...

linux/bash tips for developers?

Possible Duplicates: Favourite command line trick useful linux commands for programmers? What is your single most favorite command-line trick using Bash? I have recently become accustomed to doing most of my development (in various languages) from the bash shell, using command-line tools and interfaces. I have discovered it ...

List files with certain extensions with ls and grep

I just want to get the files from the current dir and only output .mp4 .mp3 .exe files nothing else. So I thought I could just do this: ls | grep \.mp4$ | grep \.mp3$ | grep \.exe$ But no, as the first grep will output just mp4's therefor the other 2 grep's won't be used. Any ideas? PS, Running this script on Slow Leopard. ...

awk '{print $9}' the last ls -l column including any spaces in the file name.

How would I get awk to output $9 $10 $11 etc as some of my files have spaces in them. ls -l | grep ^- | awk '{print $9}' ...

git-completion.bash displays HEAD only.

I put original git-completion.bash (from git tarball) and source it from my ~/bash_profile. When using git branch is shows only HEAD, e.g.: piotr@PiotrMBP ~/Projects/X (master) $ git co HEAD but I have: $ git br -a NSXMLDocument * master origin/HEAD origin/NSXMLDocument origin/master I haven't modified git-completion.ba...

How to run my own programm using command in Shell?

I just learned that I could use chmod make myscript.sh executable and the run it as $ ./myscript.sh But how can I attach a custom command to it, like $ connectme [options] ? ...

How to verify if an arg is a valid file name in Shell?

I need to verify if the args are valid file names, is this the right way to do it? It seems like I made some mistake inline 2, but I don't know where. for i in ${@}; do if [ -f ${i}]; then echo ${i} else continue fi done ...

How to write shell script that filter for lines and count them?

I have a text file like this: Apple Orange Orange Banana Banana Orange Banana Orange Apple Orange I want to produce the following output after running a bash shell script: Apple: 2 Orange: 5 Banana: 3 It's pretty standard stuff if I use a full blown language like Java/C++ etc but what is the quickest way to do it with a shell scrip...

Literal quotes in flags for a command in a bash script

I'm writing a Bash script in which I am running a perl script which requires flags that have double quotes in them. Running the script normally, you would run $ perl script.pl -flag="something" -anotherflag="somethingelse" In my script, I'm using variables in these flags, but would like to preserve the doublequotes, so I have somethin...

check unix username and password in a shellscript

Hi, I want to check in a shell script if a local unix-user's passed username and password are correct. What is the easiest way to do this? Only thing that I found while googling was using 'expect' and 'su' and then checking somehow if the 'su' was successful or not. ...

Writing my own shell... stuck on pipes?

Hi guys, For the past few days I have been attempting to write my own shell implementation but I seem to have gotten stuck on getting pipes to work properly. I am able to parse a line and fork off the commands between the pipes (ex: ls | sort) individually but can't seem to get them to pipe input from one into the other. I think I jus...

How to respond to password prompt when using SCP in a shell script?

First of all, I am well aware of that there are many of questions regarding this topic. I have read them, but still could figure out an appropriate answer for my situation. I would like to scp the entire ~/cs###/assign1 dir from local to school home dir with a shell script. My question is, is there a way in my script to wait for the pas...

Is this a valid shell sed command and what does it do?

sed 's/\([ab]\)\([ab]\)./\2\1x/g' file.txt My understanding is: in file.txt, find any string start with either 'a' or 'b', followed by either an 'a' or a 'b', followed by any ONE char (say 'abc'), and replace it with the string 1st, and 2nd char switched palce, and 3rd char is x ('bax'). Is the syntax of the command correct? and am I c...

Global environment variables in a bash script

How to set a global environment variable in a bash script? If I do stuff like #!/bin/bash FOO=bar ...or #!/bin/bash export FOO=bar ...the vars seem to stay in the local context, whereas I'd like to keep using them after the script has finished executing. ...

using OR in awk

I use the following two commands to see my tables from binlogs. mysqlbinlog mysql-bin.000016 | awk '/session/,/;/' | more mysqlbinlog mysql-bin.000016 | awk '/session_log/,/;/' | more How do I see both the table lines in a single statement? ...

How to split one string into multiple strings in bash shell?

I have a string, like a sentence, and I know for sure that there are many words with at least one space separate every adjacent two. How can I split the words into individual strings so I can loop through them? EDIT: Bash The string is passed in as an argument. e.g. ${2} might be "cat '' cat '' file". so how can I loop through this ar...

how to check if a string has spaces in bash shell

say a string might be like "a b '' c '' d", how can I check that there is single/double quote and space contained in the string? ...

compile the entire bash shell into my app

Hi I want to know how i compile the entire bash shell into my app.I read somewhere that for this i compile its Subroutine. how? Thanks in advance ...

How to get environment variable in 64 bit Windows?

Is there any way to retrieve the environment variable in 64 bit machine. I already have %abc% which returns me variable in 32 bit machine, but doesn't work in 64 bit. My Mistake: How can I get through command line not through programming language? ...