I have a very inefficient awk below that I need some help improving. Basically, there are three parts, that ideally, could be combined into one search and one output file. Thank you .
Part 1:
Check if the user inputted string contains + or - in it and if it does the input is writting to a file "input" and displayed on screen.
Part 2:
Looks within that "input" file for any lines with a + or - and if found writes them to a new file (temp+ or temp-)
Part 3:
Removes the + or - lines from the "input" file.
Last edited by cmccabe; 04-11-2016 at 05:23 PM..
Reason: added details
You say you only want one output file, but your current procedures are producing three output files (plus the text written to standard output). Which one output file do you want? Is it C:/Users/cmccabe/Desktop/Python27/input.txt, c:/Users/cmccabe/Desktop/Python27/temp+.txt, or c:/Users/cmccabe/Desktop/Python27/temp.txt?
This User Gave Thanks to Don Cragun For This Post:
Currently, there are three output files because the awk searches for the + and writes it to a the "input" file. Then searches for the - and writes it to "input" file. The sed then outputs a separate file for each... one for + one for - and the original input. Only the original "input" file is needed, but I am not sure how to search for both +/- at the same time. Then both, if found, would result in the "input" file. I hope this helps and thank you .
Currently, there are three output files because the awk searches for the + and writes it to a the "input" file. Then searches for the - and writes it to "input" file. The sed then outputs a separate file for each... one for + one for - and the original input. Only the original "input" file is needed, but I am not sure how to search for both +/- at the same time. Then both, if found, would result in the "input" file. I hope this helps and thank you .
No...
If we go back and look at the steps in your 1st post:
Quote:
Part 1:
Check if the user inputted string contains + or - in it and if it does the input is writting to a file "input" and displayed on screen.
This copies lines found in the file input.txt (ignoring the directory part) that contain a + or a - and writes those lines to your terminal (or to whatever file you might redirect the output). Nothing is read from a user inputted string and nothing is written to any file (unless you redirect the output from the above commands to another file).
This can be simplified to:
if you don't mind having the output from lines containing + and - characters mixed together instead of having all + printed before any lines containing - and if you don't mind just getting one output line if a line in input.txt contains both a + and a -.
Quote:
Part 2:
Looks within that "input" file for any lines with a + or - and if found writes them to a new file (temp+ or temp-)
Again, this looks at the same input file (not at any user supplied string and not at the output produced by Part 1). It copies lines from that input file (without the text added to the ends of the selected lines by Part 1) that contain + to temp+.txt and lines that contain - to temp-.txt. Part 1 and Part 2 can be combined into the single script:
Quote:
Part 3:
Removes the + or - lines from the "input" file.
Yes, that is what this does (assuming that you are using a system that has a sed that includes the -i option and that no errors occur while either of those sed commands are running).
So, if what you want to do is:
Copy lines from input.txt that contain + to temp+.txt,
copy lines from input.txt that contain - to temp-.txt,
print lines from input.txt that contain + or - or both to standard output with the added text is an intronic variant, and
remove lines from input.txt that contain a + or a - or both.
you could try just using:
This User Gave Thanks to Don Cragun For This Post:
I will try it out today. If the search of the input file contain both the + and -, then another command would remove any lines with a + or - in the input file and copy the + or - lines to a temp file. Thank you very much .
Dear Perl users/experts,
Could somebody help me how to solve my problem, I have a hash variable that I want to convert into dot file (graphviz).
I know how to convert it to dot file but I need some modification on the output of the hash variable before convert it to dot file.
Eeach key of... (1 Reply)
Hello,
Attached is my very simple C++ code to remove any substrings (DNA sequence) of each other, i.e. any redundant sequence is removed to get unique sequences. Similar to sort | uniq command except there is reverse-complementary for DNA sequence. The program runs well with small dataset, but... (11 Replies)
I have a shell script that is currently transferring a csv file from a server into a Teradata database table. One of the 30 or so columns is called "destination_url". In that URL there are parameters, and it is possible for those parameters to be repeated because of referring companies copying... (3 Replies)
I have number in file which contains date and serial number:
2013101000.
The last two digits are serial number (00). So maximum of serial number is 100.
After reaching 100 it becomes 00 with incrementing 10 which is day with max 31.
after reaching 31 it becomes 00 and increments 10... (31 Replies)
I have the following awk one-liner I came up with last night to gather some data. and it works pretty well (apologies, I'm quite new with awk, and don't know how to format this pretty-printed). You can see the output with it.
awk '{if ($8 == 41015 && $21 == "requests") arr+=$20;if ($8 == 41015... (3 Replies)
Hey guys,
Sorry for the basic question but I have a lot of files that I want to separate into groups based on filenames which I can then cat together. Eg I have:
(a_b_c.txt)
WB34_2_SLA8.txt
WB34_1_SLA8.txt
WB34_1_DB10.txt
WB34_2_DB10.txt
WB34_1_SLA8.txt
WB34_2_SLA8.txt
77_1_SLA8.txt... (1 Reply)
I am afraid I don't understand awk well enough to do the following.
I have a file with a bunch of select statements where the a line starts off with this pattern:
"Last parsed SQL statement :", then continues with the select statement. At the first blank space I'd like it to stop, print that... (5 Replies)
Hi !! I've finished an awk exercise. Here it is:
#!/bin/bash
function calcula
{
# Imprimimos el mayor tamaño de fichero
ls -l $1 | awk '
BEGIN {
max = $5; # Inicializamos la variable que nos guardará el máximo con el tamaño del primer archivo
}
{
if ($5 > max){ #... (8 Replies)