remove permissions _and_ digits after those permissions - from ls listing - ls

I am using my own generated 'script' to make recursive - yet - readable listings of my audio collection on HDD - I remove permissions from list, yet I remove 1st digit after permissions letters, and second - zero size digit right before date of folders.
Everything worked OK until I met something strange. First one is normal results I get from my 'script':
ls -lAFGgRN --time-style=long-iso %1 | grep -v ^total
| sed "s/drwxr-xr-x [0-9].* [0-9] //;s/-rw-r--r-- 1//;s/-rwxr-xr-x 1//;s/-r--r--r-- 1//" > ls-laR:
2011-09-13 11:39 A Tribute To Sepultura-1998-Sepultural Feast (Blackend, BLACK089CD (8 03341 16472 7), UK, Re-Release 2004)/
./A Tribute To Sepultura-1998-Sepultural Feast (Blackend, BLACK089CD (8 03341 16472 7), UK, Re-Release 2004):
303768 2011-09-13 11:39 _log+cue+cover_.vol00+99.par2
33621224 2011-09-13 14:07 _wav_.vol000+100.par2
25106024 2011-09-13 14:07 _wv_.vol000+100.par2
1806 2011-09-13 11:39 atributetosepultura98sepulturalfeast.cue
3702 2011-09-13 18:07 atributetosepultura98sepulturalfeast.log
496212410 2011-09-13 18:24 atributetosepultura98sepulturalfeast.wv
264054 2011-09-13 14:05 cover.jpg
But names of some folders - for the reasons I don't get yet - messing up:
(7 24388 91652 3), Netherlands, 2000)/
(8 8697-64763-2 8), USA, 2012)/
--- while ls -lAFGgoN --time-style=long-iso without using sed gives this listing:
drwxr-xr-x 1 0 2012-12-09 19:44 Chumbawamba-2000-Pass It Along (Single) (EMU Electrola GmbH, 7243 8 89165 2 3 (7 24388 91652 3), Netherlands, 2000)/
drwxr-xr-x 1 0 2012-08-25 00:26 Offspring-2012-Days Go By (Columbia, Sony Music, 88697 64763 2 (8 8697-64763-2 8), USA, 2012)/
So here is the question to Gurus:
What is happening, why my 'script' works OK with one folder(s) and fails for other(s)?
ps.'ls' and 'sed' are windows binaries, that is why I use "" for quotation instead of ''.

OK, after some hours of researching, and contacting with unix fellas, final version of my 'script' that works how I supposed to, is here:
ls.exe -lAFGgoRN --time-style=long-iso --group-directories-first %1 | grep -v ^total | sed "s/^d......... [0-9]//" | sed "s/^ *[0-9] //" | sed "s/^-......... [0-9]//" > ls-laR
And what's ls-laR contain:
.:
2011-09-13 11:39 A Tribute To Sepultura-1998-Sepultural Feast (Blackend, BLACK089CD (8 03341 16472 7), UK, Re-Release 2004)/
2012-12-09 19:44 Chumbawamba-2000-Pass It Along (Single) (EMU Electrola GmbH, 7243 8 89165 2 3 (7 24388 91652 3), Netherlands, 2000)/
2012-08-25 00:26 Offspring-2012-Days Go By (Columbia, Sony Music, 88697 64763 2 (8 8697-64763-2 8), USA, 2012)/
./A Tribute To Sepultura-1998-Sepultural Feast (Blackend, BLACK089CD (8 03341 16472 7), UK, Re-Release 2004):
303768 2011-09-13 11:39 _log+cue+cover_.vol00+99.par2
33621224 2011-09-13 14:07 _wav_.vol000+100.par2
25106024 2011-09-13 14:07 _wv_.vol000+100.par2
1806 2011-09-13 11:39 atributetosepultura98sepulturalfeast.cue
3702 2011-09-13 18:07 atributetosepultura98sepulturalfeast.log
496212410 2011-09-13 18:24 atributetosepultura98sepulturalfeast.wv
264054 2011-09-13 14:05 cover.jpg
./Chumbawamba-2000-Pass It Along (Single) (EMU Electrola GmbH, 7243 8 89165 2 3 (7 24388 91652 3), Netherlands, 2000):
238196 2012-12-09 19:43 _log+cue+cover_.vol00+81.par2
9704324 2012-12-09 18:59 _wav_.vol000+200.par2
6534724 2012-12-09 18:59 _wv_.vol000+200.par2
588 2012-12-09 18:44 chumbawamba00passitalong-single.cue
1816 2012-12-09 18:44 chumbawamba00passitalong-single.log
61975146 2012-12-09 18:43 chumbawamba00passitalong-single.wv
16956 2012-12-09 19:43 cover.jpg
./Offspring-2012-Days Go By (Columbia, Sony Music, 88697 64763 2 (8 8697-64763-2 8), USA, 2012):
299028 2012-08-25 00:25 _log+cue+cover_.vol00+98.par2
45669764 2012-08-25 15:51 _wav_.vol000+200.par2
31920964 2012-08-25 15:52 _wv_.vol000+200.par2
223828 2012-08-25 00:25 cover.jpg
1671 2012-08-25 15:42 offspring12.cue
2568 2012-08-25 15:49 offspring12.log
315772732 2012-08-25 15:49 offspring12.wv
Thanks are going to all silent Gurus, whose spiritual inspirations were so much helpful to me ;)

Related

command line calendar with Monday as the first day of the week

I'm trying to figure out how to use cal command on Linux/Debian to display Monday as the first day of the week instead of Sunday.
From what I see accordingly to cal's man page
-M Weeks start on Monday.
But it doesn't seem to work on my machine:
cal -M
Usage: cal [general options] [-jy] [[month] year]
cal [general options] [-j] [-m month] [year]
ncal -C [general options] [-jy] [[month] year]
ncal -C [general options] [-j] [-m month] [year]
ncal [general options] [-bhJjpwySM] [-H yyyy-mm-dd] [-s country_code] [-W number of days] [[month] year]
ncal [general options] [-Jeo] [year]
General options: [-31] [-A months] [-B months] [-d yyyy-mm]
cal doesn't support -M option in all UNIX versions.
Alternatively, you can use ncal -M -b to get the desired output.
May 2022
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Credits:
How to display calendar in terminal with Monday as the start of the week
Unix - Monday as first day

How to make this graph (heat map like) which represents bat activity during the year depending on the time of night

I'd like to make this graph on R:
Bat activity during the year regarding the time of the night. Each yellow dot is an individual. Blue curves are the sunset and sunrise during the year
This is the plot:
My excel file looks like this.
Date Sunrise Sunset Hours_after_sunset
16/08/2020 06:34 20:56 01:05
17/07/2020 05:53 21:42 01:26
11/08/2020 06:27 21:05 02:17
30/09/2020 07:42 19:20 06:45
24/04/2020 06:31 20:49 05:01
01/07/2020 05:38 21:53 04:13
18/07/2020 05:54 21:41 01:42
04/08/2020 06:17 21:18 01:47
13/08/2020 06:30 21:02 05:14
30/06/2020 05:37 21:53 01:37
15/08/2020 06:33 20:58 01:22
04/09/2020 07:03 20:17 07:25
07/09/2020 07:07 20:11 03:30
28/06/2020 05:36 21:54 02:10
01/07/2020 05:38 21:53 04:13
19/08/2020 06:39 20:50 01:32
09/04/2020 07:01 20:26 07:11
16/05/2020 05:55 21:22 01:14
17/06/2020 05:33 21:52 05:36
22/07/2020 05:59 21:36 03:00
11/08/2020 06:27 21:05 08:42
10/08/2020 06:25 21:07 02:36
08/08/2020 06:23 21:11 07:19
05/08/2020 06:18 21:16 03:33
24/08/2020 06:46 20:40 02:12
16/08/2020 06:34 20:56 04:01
24/08/2020 06:46 20:40 04:18
19/08/2020 06:39 20:50 02:27
22/08/2020 06:43 20:44 05:00
22/08/2020 06:43 20:44 01:56
17/09/2020 07:22 19:49 06:01
Hoping you can help me.
Something like this? Plot of the data you posted, sorted by date

file manipulation unix

cat sample_file.txt(Extracted job info from Control-M)
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 7 2019 4:45 AM,Oct 7 2019 4:45 AM,1,1,Oct 6 2019 12:00 AM,Ended OK,3ppnc
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 17 2019 4:02 AM,Oct 17 2019 4:02 AM,3,1,Oct 16 2019 12:00 AM,Ended OK,3pqgq
I need to process this file into DB table(Oracle)
Bu I need to make sure that day is 2 number (example 7 to 07).
(example: Oct 07 2019 6:32 AM)
I used this command to get all the date in every line:
cat sample_file.txt | grep "," | while read line
do
l_start_date=`echo $line|cut -d ',' -f4`
l_end_date=`echo $line|cut -d ',' -f5`
l_order_date=`echo $line|cut -d ',' -f8`
echo $l_start_date
echo $l_end_date
echo $l_order_date
done
Output:
Oct 7 2019 4:45 AM
Oct 7 2019 4:45 AM
Oct 6 2019 12:00 AM
Oct 17 2019 4:02 AM
Oct 17 2019 4:02 AM
Oct 16 2019 12:00 AM
expected output:
FROM: Oct 7 2019 6:32 AM
To: Oct 07 2019 6:32 AM
I used this sed command but it add also to 2 number day (17)
sed command sed 's|,Oct |,Oct 0|g' sample_file.txt
Oct 17 was change to Oct 017
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 07 2019 4:45 AM,Oct 07 2019 4:45 AM,1,1,Oct 06 2019 12:00 AM,Ended OK,3ppnc
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 017 2019 4:02 AM,Oct 017 2019 4:02 AM,3,1,Oct 016 2019 12:00 AM,Ended OK,3pqgq
I wish it was easier, but I only managed the following:
awk.f:
function fmt(s) {
split(s,a," "); a[2]=substr(a[2]+100,2)
return a[1] " " a[2] " "a[3] " " a[4] " " a[5]
}
BEGIN {FS=",";OFS=","}
{gsub(/ +/," ");
$4=fmt($4); $5=fmt($5); $8=fmt($8);
print}
This is a little awk script that first removes superfluous blanks and then picks out particular columns (4,5 and 8) and reformats the second part of each date string into a two-digit number.
You run the script like this:
awk -f f.awk sample_file.txt
output:
upctm,pmdw_aud,pmdw_aud_ext_06-GAPAnalysYTD,Oct 07 2019 6:32 AM,Oct 07 2019 6:32 AM,17,17,Oct 06 2019 12:00 AM,Ended OK,3pu9v
upctm,pmdw_ddm,pmdw_ddm_dum_01-StartProjDCSDemand,Oct 07 2019 4:02 AM,Oct 07 2019 4:02 AM,3,1,Oct 06 2019 12:00 AM,Ended OK,3pqgq
upctm,pmdw_bip,pmdw_bip_mnt_35-FOLDistAutoRpt,Oct 07 2019 4:45 AM,Oct 07 2019 4:45 AM,1,1,Oct 06 2019 12:00 AM,Ended OK,3ppnc
With a fixed locale, you can make a fixed replacement like
sed -r 's/(Jan|Feb|Oct|Whatever) ([1-9]) /\1 0\2 /g' sample_file.txt

Converting dataframe to date format [duplicate]

This question already has an answer here:
Convert factor to date class for multiple columns
(1 answer)
Closed 5 years ago.
i have a dataframe containing 250 columns of dates and in time in character format except for column 1 which contains Employee ID id. How can i convert all the columns except 1st column to date format.
1 1/5/2015 17:20 1/6/2015 17:19 1/7/2015 16:34 1/8/2015 17:08
2 1/2/2015 18:22 1/5/2015 17:48 NA 1/7/2015 17:09
3 1/2/2015 16:59 1/5/2015 17:06 1/6/2015 16:38 1/7/2015 16:33
4 1/2/2015 17:25 1/5/2015 17:14 1/6/2015 17:07 1/7/2015 16:32
5 1/2/2015 18:31 1/5/2015 17:49 1/6/2015 17:26 1/7/2015 17:37
6 1/2/2015 20:29 1/5/2015 20:57 1/6/2015 21:06 1/7/2015 20:36
Above date and in time of employee are in character format.
Tried doing
parse_date_time(df[,-1],"ymd_HMS") and parse_date_time(df[,2:250],"ymd_HMS")
but the same is not working. However while specifying only one column the syntax is working. Practically to do for 250 codes by individually specifying each columns is bad coding.
Apply strtime function to turn your character values into datetime values.
df[,2:250] <- as.data.frame(lapply(df[,2:250], strptime, format="%Y-%m-%d %H:%M:%S"))
The df[,2:250] will take only the columns you are interested in.
The format format="%Y-%m-%d %H:%M:%S" describes the format of your character entries. You can see what the letters mean here.

How to determine the zodiac symbol in R?

I did some statistics today using Excel and R. Part of the work requires to determine the zodiac symbol according to the date of birth. I did this in Excel:
Sample data:
DOB
25-Jan-1985
25-Jul-1983
28-Aug-1982
24-Feb-1984
13-Jan-1985
24-Jan-1982
15-Feb-1984
14-Oct-1983
08-Sep-1984
04-Mar-1983
04-Apr-1984
31-Mar-1985
04-Aug-1984
29-Jan-1984
20-Jul-1984
...
Here is the rule to determine zodiac symbols:
Dec. 22 - Jan. 19 - Capricorn
Jan. 20 - Feb. 17 - Aquarius
Feb. 18 - Mar. 19 - Pisces
March 20 - April 19 - Aries
April 20 - May 19 - Taurus
May 20 - June 20 - Gemini
June 21 - July 21 - Cancer
July 22 - Aug. 22 - Leo
Aug 23 - Sept. 21 - Virgo
Sept. 22 - Oct. 22 - Libran
Oct. 23 - Nov. 21 - Scorpio
Nov. 22 - Dec. 21 - Sagittarius
Excel formula:
=LOOKUP(--TEXT(A2,"mdd"),{101,"Capricorn";120,"Aquarius";219,"Pisces";321,"Aries";420,"Taurus";521,"Gemini";621,"Cancer";723,"Leo";823,"Virgo";923,"Libran";1023,"Scorpio";1122,"Sagittarius";1222,"Capricorn"})
I'm wondering how to do it in R? Also data.table is great, is it possible to figure it out in data.table?
Assuming your data is called dat.
First, convert it to a date format:
dat$DOB <- as.Date(dat$DOB, format = "%d-%b-%Y")
Then use the Zodiac function from DescTools, as mentioned by #Josh in the comment:
library(DescTools)
dat$Zodiac <- Zodiac(dat$DOB)
dat

Resources