A shell function works like a function in any programming language. Remember, a shell is never only a commando interpreter but always a programming language as well.
If you have no experience with programming picture it like this: you create a set of commands and put a name to this collection. When you now call the name you have selected the whole collection of these commands is being replayed.
So far there is no difference between a script (=program) and a function at all. The difference is that a script always uses its own environment (it is a program in its own right), whereas a function is executed within the environment of another program. In the shell you can even "load" functions into memory and have them being executed within your shell without having to load them from disk, like a script. In this case the program within which it si executed is the command shell you are using.
Any idea if this function could work with wildcards at all?
I've tried with various wildcards so far and that doesn't seem to work.
So I could do something like... *tatus or 50**
---------- Post updated at 12:11 PM ---------- Previous update was at 11:48 AM ----------
Ok tell me if this is an accurate understanding. I was trying to grasp the difference between the alias and the function. Simply looking at them it seems the same.
But what I think is going on is that a function is it's own isolated execution. Meaning if I do.
Then in at any time I put in 'word', all that is really happening is that 'word' is removed and the other words put in the same place.
Where as a function is actually executing its own command right there which is isolated from the ones around it? Or am I completely off here?
---------- Post updated at 03:13 PM ---------- Previous update was at 12:11 PM ----------
Well I have made a little progress here. I adjusted my function a little bit in an effort to make it work with multiple words instead of just one. I have gotten this to work the problem however is that its always a fixed amount. If I use this function then I can change the color of two words but its MUST be two words or it will not work.
So i'm trying still to figure out how to simply get this to work with whatever # of words or strings I enter.
I changed it from printf to echo just to play around but either works really.
---------- Post updated at 04:40 PM ---------- Previous update was at 03:13 PM ----------
Perhaps I could use some kind of control variable and make SED loop X number of times based on that variable... So... I could do something like.
Then I use the first argument as my loop #. Then sed goes through once then subtracts one from the loop number and goes through again until the number reaches zero... Sounds complicated for a task such as this.. But for me its more about learning how all this stuff works vs how actually useful these commands wind up being in the real world.
---------- Post updated at 05:10 PM ---------- Previous update was at 04:40 PM ----------
Ok so i've gotten this far.. It works but only with 1 variable still...
---------- Post updated at 05:44 PM ---------- Previous update was at 05:10 PM ----------
Seems to be an issue with the variables.. Clearly the command is working so its getting the first variable. But ones don't seem to be coming through.
So when I do sgrep Front log error
It finds front and does what it should but there is no loop happening and its not picking up the log or error attributes...
ITS A BREAK IN THE LINE I'M LOST!!!!
Last edited by Scott; 04-21-2010 at 07:37 PM..
Reason: Please use code tags
I think your requirement is too complex to be done with an one-liner.
Here is a fully working script which can search up to 3 words.
Feel free to modify it if you need to search your logfile(s) for more than 3 words.
Thanks i'm glad you were able to get the sed command to work correctly without actually using it as a function.
I still think that my loop method seems like it should work but its not. I just need to figure out why its only taking the first argument and using it as a variable. If it would just take all 3 like I WANT IT TOO! then it would work fine and it would work for any number of works I used anytime.
The script that pseudocoder wrote i'm sure will work. Problem is that the way our systems work I'm not working on my own box. I'm working on customers boxes so I don't like having to put anything on the customers box. So almost everything I do has to be something which can be pasted into a command line. Having to FTP a file to a customers box is a no no unless its an unusual situation.
So I can't really use the script except on my own boxes at my desk.
Hello I have a script that searches a file for a specific string and then changes the nth column after that string. I have searched online for how to do this with sed but have not seemed to find a solution that works for me. I am using bash.
Some background info:
- Currently I am using awk to... (4 Replies)
Hi,
I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches.
file has lot of functions defined
a.sh
#!/bin/bash
fn a {
beautiful evening
sunny day
}
fn b {
}
fn c {
hello world .its a beautiful day
... (12 Replies)
I'm try to change a the prohibit to aix for the lines starting with ssh and emagent and rest should be the same. Can anyone please suggest me how to do that using a shell script or sed
passwd account required /usr/lib/security/pam_prohibit
passwd session required ... (13 Replies)
Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately.
Here's some example output:
Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop
bond0 9 83830... (3 Replies)
Hello,
I am using RHEL 6.1 on VMware
I am searching for a way to change background color (not line by line color wich one can using tput command)
basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
I have http log that I want to get words after specific "tag", this a sample line from the log:
98,POST,200 OK,www.facebook.com,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,/ajax/updatestatus.php?__a=1,datr=P_H1TgjTczCHxiGwdIF5tvpC; lu=Si1fMkcrU2SInpY8tk_7tAnw;... (6 Replies)
Hi,
I have gone through may posts and dint find exact solution for my requirement.
I have file which consists below data and same file have lot of other data.
<MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'>
<MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
My source is on each line
98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Hello,
I have this file.
aaa
port=1234
time
bbb
port=2233
name
ccc
port=4444
name
Is there any way with sed to change only the occurence of "port" which comes after section to have as output : (12 Replies)
GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32
I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)