Here is exactly what you may be looking for.
Above code will create a backup for main_file with name main_file_Original and remvove non-matching lines from main_file too, let me know if this helps you.
Thanks,
R. Singh
I just tested the code as follows (adapted to my enviroment)
but it does not seem to create the files. The error i am getting is as follows:
awk: 1: unexpected character '.'
awk: 1: unexpected character '.'
awk: cannot open /srv/prijslijst/lev/raw4.csv (No such file or directory)
I tried changing the $PAD variable to the dir itself but it does not change the output. From the shell itself it works fine.
I just tested the code as follows (adapted to my enviroment)
but it does not seem to create the files. The error i am getting is as follows:
awk: 1: unexpected character '.'
awk: 1: unexpected character '.'
awk: cannot open /srv/prijslijst/lev/raw4.csv (No such file or directory)
I tried changing the $PAD variable to the dir itself but it does not change the output. From the shell itself it works fine.
Hello SDohmen,
In awk assigning variables value will not be like shell ones. Could you please try following and let me know if this helps you.
Thanks,
R. Singh
In awk assigning variables value will not be like shell ones. Could you please try following and let me know if this helps you.
Thanks,
R. Singh
I think i figured it out. The code above did not create the files either so i googled a bit and found out that the changed code like below works.
Thank you for helping with the code.
Quote:
Originally Posted by RudiC
Did you look for two files called "Positive" and "Negative" in your pwd?
I overlooked those 2 as i thought it where text inline with the files . Later on i noticed it created 2 files named positive and negative. Sorry for overlooking that
---------- Post updated 11-02-16 at 09:47 AM ---------- Previous update was 10-02-16 at 03:16 PM ----------
Here i am again. I tested the code with 1 of the things i needed filtering and it works just fine.
Now i am struggling with the other filter though. Same as before i need too filter lines from 1 file to 2 others. The difference here is that the filter file has words in it in which some have spaces like below:
And the other problem is that these words can be anywhere in the file. I tried using the awk line from before and let it run on each colomn seperatly but it seems that it looks for each word seperatly creating false negatives. Any idea how i best can solve this?
I know i can do this with grep but its awefull slow and gives problems with too many lines.
---------- Post updated at 09:57 AM ---------- Previous update was at 09:47 AM ----------
Sorry i forgot to add some samples.
Main file
This main file is different in most cases but that is mainly the delimiter which i should be able to handle.
filter file
With above samples it should filter the last line from the main file (and put it in a seperated file) because of the word(s) "Wireless Desktop" but not the line above which only contains "Wireless".
Not sure how to discriminate this new problem from the other. Does it come on top or in place? Some decent samples could help.
I am not 100% sure what you mean but i added sample data.
In total i have 2 filters which run over different stages of the same file.
The word filter will be run first as that is when i still have all the data to look for those. After that it will be cut and processed to a near finished file which then filters against the other EAN filter to remove the last lines which arent needed.
Technically it should be fine if they are in 1 filter file (and loop in the beginning) but that would probably make the code really complicated i guess.
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)
In the awk below I am trying to remove all lines above and including the pattern Test or Test2. Each block is seperated by a newline and Test2 also appears in the lines to keep but it will always have additional text after it. The Test to remove will not. The awk executed until the || was added... (2 Replies)
Hi,
I'd be grateful for your help with the following. I have a file (file.txt) with 10 columns and about half a million lines, which in simplified form looks like this:
ID Col1 Col2 Col3....
a 4 2 8
b 5 6 1
c 8 4 1
d... (4 Replies)
I am trying to remove each line in which $2 is FP or RFP. I believe the below will remove one instance but not both. Thank you :).
file
12
123 FP
11
10 RFP
awk
awk -F'\t' '
$2 != "FP"' file
desired output
12
11 (6 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)
I have a file like this - I want to remove the 2015 (or any four digit #) from column $4 so I can get:
Nov 05 1997 /ifs/inventory2/
for example. Im not sure how. Should I use an if statement with awk?
Jan 16 2015 23:45 /ifs/sql_file
Jan 16 2015 23:45 /ifs/sql_file
Nov 05 2015 1997... (4 Replies)
I need to send email to receipient in each block of data in a file which has the sender address under TO and just send that block of data where it ends as COMPANY.
I tried to work this out by getting line numbers of the string HELLO but unable to grab the next block of data to send the next... (5 Replies)
Hi,
I need to get specific parts in a large file.
I need to:
Get a line containing an IP address, and read from there to another line saying ***SNMP-END***
So, I have the start and the end well defined, but the problem is that apparently the awk command using the -F option doesn't work... (17 Replies)
hi,,
i hav a file with many lines.i need to remove all lines before a line begginning with a specific pattern from the file because these lines are not required.
Can u help me out with either a perl script or shell script
example:-
if file initially contains lines:
a
b
c
d
.1.2
d
e
f... (2 Replies)
I want to search a file for a string and then if the string is found I need the line that the string is on - but also the previous two lines from the file (that the pattern will not be found in)
This is on solaris
Can you help? (2 Replies)