If I could get any explanations on why the code below doesn't work it would be great !
My input looks like that ("|" delimited):
The goal is, if $2 is "ok", to remove everything before the pattern given in the match function below. Otherwise keep the original string in $1:
in order to get:
But when the record matches $2 but not the regex inside "match", I don't understand why it removes the first character:
If someone could explain that to me please.
As far as I know awk match function syntax is:
I noticed that your are passing 3 arguments for match function which is wrong!
That is incorrect. Check manual page for gawk.
@OP:
Check this:
Do you get it? If no, check the explanation of match function in gawk's man page (specifically the manner in which the 3rd argument (array) is populated).
Last edited by elixir_sinari; 05-25-2013 at 03:29 PM..
This User Gave Thanks to elixir_sinari For This Post:
Hmmmm - the requestor didn't ask for alternative solutions, he asked to explain why that "strange" behaviour occurred (which, btw, is not strange but correct). Let's go and try: According to the gawk man page, the array f will be filled with "the matches". The first match ( f[1] ) is being used as a separator in the following split, and then the chars before the first match (array[1]) will be substituted with "".
If there's no match, like in the second line, f will be empty, and split will use an empty separator, resulting in a per char split. array[1] will then hold the "S" which will be removed.
Logical, understandable?
I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for:
my.cnf
/bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf
after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Hi, everyone.
I need to write a program to get io info based on libperfstat.
But the "write time" of a disk is just half of the value get from iostat.
I'm confused and can't explain. Help please.
How I calculate "write service time per sec":
In iostat:
write service... (0 Replies)
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
Looking for awk statement that will match all lines starting with "# "
if ( $1 == \^"#" )
Input file:
# of the server. If you would like to set these, please take out the
# pound (#) sign in front of one or all severities and set it equal to
# severity desired. For example, FATAL=3
#... (2 Replies)
Hi Friends,
Can any of you explain me about the below line of code?
mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`
Im not able to understand, what exactly it is doing :confused:
Any help would be useful for me.
Lokesha (4 Replies)