I've a file with 17 column. I need to filter this file. For example, if the data in column number 2, is smaller than 4, or it's a word, the programa must delete the line.
The following may be irrelevant, but I point it out as a heads up, just in case.
Quote:
Originally Posted by panyam
That expression will match non-numeric data that's not alphabetical. If that is undesirable, I would recommend either using a complemented decimal digit class, [^0-9], or going with danmero's approach.
Also, durden_tyler's perl solution is a bit more accepting:
Regards,
Alister
---------- Post updated at 12:03 PM ---------- Previous update was at 11:49 AM ----------
I do not recommend using the following in production, as it's not immediately obvious what it does, but I share it in the spirit of AWK golf.
Dedicated to danmero :
For AWK novices, the parenthetical tests whether or not the value in $2 is a non-numeric string. $2+0 forces a conversion to a numeric value. When the result is compared to $2 with ==, if $2 is a numeric value, then two idential numbers are compared and the result of the comparision is 1. Multiplying $2 by 1 doesn't alter the result of the comparison with 3.
However, if $2 is a non-numeric string, the result of $2+0 (a number) will not be identical to $2 (a string), because the conversion process will have discarded the non-numeric portions of the string. When AWK compares the two with ==, it will not be comparing two numbers. When one value in a comparison is a non-numeric string, the other is converted (if necessary) to a string before the comparison. In this case, the result is a comparison between two unidentical strings, which yields the number 0. 0>$3 is false and the line is skipped.
This approach allows floating point values in $2, while the int() approach does not. I only mention this for the sake of being thorough in this description, not to tout it as an advantage.
If nothing else, that AWK snippet makes for a good lesson in AWK type conversion
Hello,
I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below).
Example:
one
two
three
four
five
six
seven
eight
I want it to look like: (6 Replies)
hey guys,
I tried searching but most 'search and replace' questions are related to one liners.
Say I have a file to be replaced that has the following:
$ cat testing.txt
TESTING
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
ENDTESTING
This is the input file: (3 Replies)
Hi All,
I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space.
I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Hello,
I have a group of text files with many lines in each file.
I need to delete all the lines in each and only leave 2 lines in each file. (3 Replies)
First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible )
I got a file (trace file to recreate the control file from oracle for the dba boys)
which contains
some lines
another line... (11 Replies)
Input:
a
b
b
c
d
d
I need:
a
c
I know how to get this (the lines that have duplicates) :
b
d
sort file | uniq -d
But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Hi
I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings.
Ex: file name 'test'
test:
approved package
waiting for approval package
disapproved package
removed package
approved... (14 Replies)
Hi
I want to delete first five and last five lines in text files without opening the file and also i want to keep the same file name for all the files.
Thanks in advance!!!
Ragav (10 Replies)