How to display task without due date before the task with due date - taskwarrior

I want to display the task in descending order of due date (as I have a long list of tasks and want to have the ones with lowest due date at first and not having to scroll up to see them) and therefore display the task without due date before the task with due date.
Here is the content of my .taskrc file
data.location=~/.tasktest
report.simple.columns=id,project,due,urgency
report.simple.sort=due-
report.simple.filter=status:pending
Here is the content of the file pending.data:
[description:"description1_2: blablabla blablabla blablabla blablabla blablabla blablabla blablabla" due:"1625954400" entry:"1625487626" modified:"1625823811" project:"project1.subproject1_2" status:"pending" tags:"tag1,tag2" uuid:"e28d104a-4fca-46a9-8468-200407fa02e7"]
[description:"description1_1 blablabla blablabla blablabla blablabla blablabla blablabla blablabla" due:"1625695200" entry:"1625492019" modified:"1625823829" project:"project1.subproject1_1" status:"pending" tags:"tag1" uuid:"f1458cc3-0fb8-467f-a7b4-743fa72f8706"]
[description:"description3_1: blablabla blablabla blablabla blablabla blablabla blablabla blablabla" due:"1627164000" entry:"1625501018" modified:"1625823844" project:"project3.subproject3_1" status:"pending" uuid:"b3d974ec-4871-4258-a1a7-ac5ebee42840"]
[description:"blablabla blablabla blablabla blablabla blablabla blablabla blablabla" due:"1626732000" entry:"1625520776" modified:"1625583092" project:"project2.subproject2_1.subproject2_1_2" status:"pending" uuid:"f9e18d14-d628-40bc-a58b-43bdbe3cf815"]
[description:"blablabla blablabla blablabla blablabla blablabla blablabla blablabla" entry:"1625520879" modified:"1625824409" project:"project2.subproject2_1.subproject2_1_3" status:"pending" uuid:"2caf1eec-b33f-4cf7-8d55-5c5b0f1c835c"]
[description:"description_5" entry:"1625824928" modified:"1625824928" project:"project5" status:"pending" uuid:"c943be0b-3491-4d0e-a092-aba9666044bf"]
Here is the current output of task simple(output n°1):
ID Project Due Urgency
-- -------------------------------------- ---------- -------
3 project3.subproject3_1 2021-07-25 3.42
4 project2.subproject2_1.subproject2_1_2 2021-07-20 5.02
1 project1.subproject1_2 2021-07-11 10
2 project1.subproject1_1 2021-07-08 11.3
5 project2.subproject2_1.subproject2_1_3 1.02
6 project5 1
6 tasks
want I want is to display the tasks 5 and 6 before the tasks 3,4,1,2 as follows (output n°2):
ID Project Due Urgency
-- -------------------------------------- ---------- -------
5 project2.subproject2_1.subproject2_1_3 1.02
6 project5 1
3 project3.subproject3_1 2021-07-25 3.42
4 project2.subproject2_1.subproject2_1_2 2021-07-20 5.02
1 project1.subproject1_2 2021-07-11 10
2 project1.subproject1_1 2021-07-08 11.3
6 tasks
How could I obtain the output n°2?

What you want can be done by leveraging urgency. I believe that this truly matches your intent, even though the question is strictly asking for sorting by due date.
As you can already see in your desired output example, it's already sorted by urgency. You can change report sorting to:
report.simple.sort=urgency-
Urgency uses coefficients for each property, the default for urgency.due.coefficient is 12.0. Play with this value for your workflow, as urgency is influenced by other properties such as priority or depends: increasing the weighting will make tasks that are due soon have higher score.

Related

Print the fist row with check the condition in awk command

File in content is
safwan#hello:~/linx$ cat 5.txt
Name age address email
safwan 25 India safwan#gmail.com
Ajmal 23 India ajmal#gmil.com
Apply a condition
awk '$2==25 {print}' 5.txt
output is
safwan#hello:~/linx$ awk '$2==25 {print}' 5.txt
safwan 25 India safwan#gmail.com
But I need also the first row
I expect the output is like
Name age address email
safwan 25 India safwan#gmail.com
You can evaluate if NR == 1 or your actual condition to get the header row with your data row:
awk 'NR == 1 || $2 == 25' 5.txt
Besides there is no need to use {print} as that is the default action in awk.

Using awk to include file name with format in column

I'm working on wrangling some data to ingest into Hive. The problem is, I have overwrites in my historical data so I need to include the file name in the text files so that I can dispose of the duplicated rows which have been updated in subsequent files.
The way I've chosen to go about this is to use awk to add the file name to each file, then after I ingest into Hive I can use HQL to filter out my deprecated rows.
Here is my sample data (tab-delimited):
animal legs eyes
hippo 4 2
spider 8 8
crab 8 2
mite 6 0
bird 2 2
I've named it long_name_20180901.txt
I've figured out how to add my new column from this post:
awk '{print FILENAME (NF?"\t":"") $0}' long_name_20180901.txt
which results in:
long_name_20180901.txt animal legs eyes
long_name_20180901.txt hippo 4 2
long_name_20180901.txt spider 8 8
long_name_20180901.txt crab 8 2
long_name_20180901.txt mite 6 0
long_name_20180901.txt bird 2 2
But, being a beginner, I don't know how to augment this command to:
make the column name (first line) something like "file_name"
implement regex in awk to just extract the part of the file name that I need, and dispose of the rest. I really just want "long_name_(.{8,}).txt" (the stuff in the capturing group.
Target output is:
file animal legs eyes
20180901 spider 8 8
20180901 crab 8 2
20180901 mite 6 0
20180901 bird 2 2
Thanks for your time!! I'm a total newbie to awk.
This would handle one or multiple input files:
awk -v OFS='\t' '
NR==1 { print "file", $0 }
FNR==1 { n=split(FILENAME,t,/[_.]/); fname=t[n-1]; next }
{ print fname, $0 }
' *.txt
You can use BEGIN that sets the "file" and then reset it to use the filename for the rest.
awk 'BEGIN{f="file\t"} NF{print f $0; if (f=="file\t") {l=split(FILENAME, a, /[_.]/); f=a[l-1]"\t"};}' long_name_20180901.txt

How do I scrape website data into excel BUT append the results to log

I have a device connected to local intranet, that will display various data values when requested. It's a very simple format. I can request the information in a web browser, or in Excel with a "get external data from web".
{
"parameter 1": 1234,
"parameter 2": -23,
"parameter 3": 20818,
...etc
}
The problem is that it just displays the information requested, but no history. It just overwrites the new values over the old, and will only to it once per minute.
I would like to be able to use the parameters as column headers, and the values to keep appending to new rows every 1 to 10 seconds.
Timestamp | parameter 1 | parameter 2 | parameter 3
---------------------------------------------------------
8:00:00 | 1234 | -23 | 20818
8:00:01 | 1235 | -23 | 19800
8:00:02 | 1245 | -23 | 18550
Is there a way to do this in excel?

How to print the lines that contains certain strings by order?

I have two files
file indv
COPDGene_P51515
COPDGene_V67803
COPDGene_Z75868
COPDGene_U48329
COPDGene_R08908
COPDGene_E34944
file data
COPDGene_Z75868 1
COPDGene_A12318 3
COPDGene_R08908 5
COPDGene_P51515 8
COPDGene_U48329 2
COPDGene_V67803 8
COPDGene_E34944 2
COPDGene_D29835 9
I want to print the lines that contains the strings in the indv by the order of indv like following
COPDGene_P51515 8
COPDGene_V67803 8
COPDGene_Z75868 1
COPDGene_U48329 2
COPDGene_R08908 5
COPDGene_E34944 2
I tried to use
awk 'NR==FNR{a[$1]++;next} ($1 in a)' indv data
But I got
COPDGene_Z75868 1
COPDGene_R08908 5
COPDGene_P51515 8
COPDGene_U48329 2
COPDGene_V67803 8
COPDGene_E34944 2
which is not the order of indv.
$ awk 'FNR==NR{a[$1]=$0;next;} {print a[$1]}' data indv
COPDGene_P51515 8
COPDGene_V67803 8
COPDGene_Z75868 1
COPDGene_U48329 2
COPDGene_R08908 5
COPDGene_E34944 2
How it works
FNR==NR{a[$1]=$0;next;}
For the first file read, data, save each line in associative array a under the index of its first field, $1. Skip the rest of the commands and start over on the next line.
print a[$1]
If we get here, we are working on the second file, indv. For this file, print each line from data that corresponds to the first field on this line. In this way, the contents of each line is controlled by data but the order of printing is controlled by indv.
awk 'FNR==NR{a[$1]=$2;next} a[$1]{print $1,a[$1]}' data indv
COPDGene_P51515 8
COPDGene_V67803 8
COPDGene_Z75868 1
COPDGene_U48329 2
COPDGene_R08908 5
COPDGene_E34944 2
Advantages: Only the second field is stored in memory, instead of the full record from data. It does not try to print a record from indv that does not have a match in data.
Disadvantages: It will keep only the last entry from data, if the lines were not unique.

Compare one field, Remove duplicate if value of another field is greater

Trying to do this at linux command line. Wanting to combine two files, compare values based on ID, but only keeping the ID that has the newer/greater value for Date (edit: equal to or greater than). Because the ID 456604 is in both files, wanting to only keep the one from File 2 with the newer date: "20111015 456604 tgf"
File 1
Date ID Note
20101009 456604 abc
20101009 444444 abc
20101009 555555 abc
20101009 666666 xyz
File 2
Date ID Note
20111015 111111 abc
20111015 222222 abc
20111015 333333 xyz
20111015 456604 tgf
And then the output to have both files combined, but only keeping the second ID value, with the newer date. The order of the rows are in does not matter, just example of the output for concept.
Output
Date ID Note
20101009 444444 abc
20101009 555555 abc
20101009 666666 xyz
20111015 111111 abc
20111015 222222 abc
20111015 333333 xyz
20111015 456604 tgf
$ cat file1.txt file2.txt | sort -ru | awk '!($2 in seen) { print; seen[$2] }'
Date ID Note
20111015 456604 tgf
20111015 333333 xyz
20111015 222222 abc
20111015 111111 abc
20101009 666666 xyz
20101009 555555 abc
20101009 444444 abc
Sort the combined files by descending date and only print a line the first time you see an ID.
EDIT
More compact edition, thanks to Steve:
cat file1.txt file2.txt | sort -ru | awk '!seen[$2]++'
You didn't specify how you'd like to handle the case were the dates are also duplicated, or even if this case could exist. Therefore, I have assumed that by 'greater', you really mean 'greater or equal to' (it also makes handling the header a tiny bit easier). If that's not the case, please edit your question.
awk code:
awk 'FNR==NR {
a[$2]=$1
b[$2]=$0
next
}
a[$2] >= $1 {
print b[$2]
delete b[$2]
next
}
1
END {
for (i in b) {
print b[i]
}
}' file2 file1
Explanation:
Basically, we use an associative array, called a, to store the 'ID' and 'Date' as key and value, respectively. We also store the contents of file2 in memory using another associative array called b. When file1 is read, we test if column two exists in our array, a, and that the key's value is greater or equal to column one. If it is, we print the corresponding line from array b, then delete it from the array, and next onto the next line/record of input. The 1 on it's lonesome will return true, thereby enabling printing where the previous (two) conditions are not met. This has the effect of printing any unmatched records from file1. Finally, we print what's left in array b.
Results:
Date ID Note
20111015 456604 tgf
20101009 444444 abc
20101009 555555 abc
20101009 666666 xyz
20111015 222222 abc
20111015 111111 abc
20111015 333333 xyz
Another awk way
awk 'NR==1;FNR>1{a[$2]=(a[$2]<$1&&b[$2]=$3)?$1:a[$2]}
END{for(i in a)print a[i],i,b[i]}' file file2
Compares value in an array to previously stored value to determine which is higher, also stores the third field if current record is higher.
Then prints out the stored date,key(field 2) and the value stored for field 3.
Or shorter
awk 'NR==1;FNR>1{(a[$2]<$1&&b[$2]=$0)&&a[$2]=$1}END{for(i in b)print b[i]}' file file2

Resources