As my home work, I tried to figure it out how it works (though I know it works) but still no luck:-( Would someone elabrate a little of the syntax for me?[...]
In awk, uninitialized variables ("no" in our case) have the numeric value zero, which in awk means false
therefore the following code means IF (0) AND /str/ (the current record contains the pattern "str"), which means IF FALSE AND TRUE (true for the records that contain the pattern), then skip this record (that's the meaning of the "next" statement).
FALSE AND TRUE == FALSE (it would have been true if both elements were true), so, the records that contain the pattern "str" before we set the variable no to 1 (which in awk means TRUE) are not affected, nothing happens:
The following code means: if the current record contains the pattern "The F", assign the value 1 to the variable no, then skip the record ("next"):
Then we need just: 1 (TRUE), in awk this means use default action,
which is print the current record (not affected/skipped! by the previous actions):
We can write all this also as:
Thank you so much! Now that I understand how it works, I'm actually able to add a little more to it to solve the problem I had (removing all the lines including different keywords):
nawk 'no&&/str1|str2|str3|...../{next};/The F/{no=1;next}1' filename
However, when I tried to run this line it compaint syntax error:
awk '/The F/,0{if($0~/str/)next}1' filename
I tried to fix with no luck:-(
I think I was able to recognize the second part- if there is a matching pattern(str) found in current line($0), skip it(next) otherwise print (1).
But I don't know how to interpret the first half. Please help me;-)
[...]
However, when I tried to run this line it compaint syntax error:
awk '/The F/,0{if($0~/str/)next}1' filename
I tried to fix with no luck:-(
If you are on Solaris, you have to use nawk or /usr/xpg4/bin/awk,
not the old broken /usr/bin/awk.
Quote:
I think I was able to recognize the second part- if there is a matching pattern(str) found in current line($0), skip it(next) otherwise print (1).
But I don't know how to interpret the first half. Please help me;-)
Right,
the first part is a range selector: start,end - from the pattern "The F" to 0 (0 is false, so to the end of the file(s)).
In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :).
grep
grep -v -F -f targets.bed sort_list
grep -vFf sort_list targets
awk
awk -F, '
> FILENAME == ARGV {to_remove=1; next}
> ! ($5 in... (2 Replies)
Hi,
I have requirement that I need to split my input file into two files based on a search pattern "abc"
For eg. my input file has below content
abc
defgh
zyx
I need file 1 with
abc
and file2 with
defgh
zyx
I can use grep command to acheive this. But with grep I need... (8 Replies)
I have searched the forum for this - forgive me if I missed a previous post.
I have the following file:
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
alter table "informix".esc_acct add constraint (foreign key (fi_id)
references "informix".fi ... (5 Replies)
Hello,
I've to change the shell in /etc/passwd for some users .
I've the list of users but I'm not able to modify the file with scripting .
I'm working on a Sol10 .
Can anyone help me ?
tnks (7 Replies)
Can anyone tell me what could be the solution to following :
I have one .txt file which contains some "seed" information. This seed may appear multiple time in the file so what I want do is if this seed appears again in the file then that line should be removed.
Please provide the script code... (4 Replies)
Hi there
I have a file with a variable amount of rows but the 45th, 46th and 47th charachter of each line is the status field which is a three digit code ie 001, 002, 003 etc. My question is this..I need to strip all the records/lines with 002's out of the file completely and put them into... (14 Replies)