Some time ago I copied a bash shell script from a site which I cannot trace. It was written in bash and awk and was not good but superb ! It was about 25 lines long. I had made it into a function and was using it regularly but in a change of distro I lost it . Can anyone help?
-
-
function lso {
-
ls -l | awk '{
-
k = 0
-
s = 0
-
for( i = 0; i <= 8; i++ )
-
{
-
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
-
}
-
j = 4
-
for( i = 4; i <= 10; i += 3 )
-
{
-
s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j )
-
j/=2
-
}
-
if ( k )
-
{
-
printf( "%0o%0o ", s, k )
-
}
-
print
-
}'
-
}
-
-
function lsa {
-
ls -al | awk '{
-
k = 0
-
s = 0
-
for( i = 0; i <= 8; i++ )
-
{
-
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
-
}
-
j = 4
-
for( i = 4; i <= 10; i += 3 )
-
{
-
s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j )
-
j/=2
-
}
-
if ( k )
-
{
-
printf( "%0o%0o ", s, k )
-
}
-
print
-
}'
-
}
-
Similar but different.
ashitpro,IRYHS !
5 2666
@pwilliams,
Can you give us an example of what the script did?
Your description isn't very clear. We know something about processing ls output into octal. However a concrete request might help.
I believe you need output permissions in octal format ?
for example if original output is: - -rw-r--r-- 1 root root 24405 Sep 20 16:56 a.txt
you need it like this: - 644 -rw-r--r-- 1 root root 24405 Sep 20 16:56 a.txt
If this is what you wanted then you can use; - ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}'
Oralloy ,ashitpro many thanks for your replies.
With a red face I must confess,the file came to light in a totally wrong directory , on a usb stick I had forgotten about.Would anybody be interested in seeing it?
send the function you are talking about.
-
-
function lso {
-
ls -l | awk '{
-
k = 0
-
s = 0
-
for( i = 0; i <= 8; i++ )
-
{
-
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
-
}
-
j = 4
-
for( i = 4; i <= 10; i += 3 )
-
{
-
s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j )
-
j/=2
-
}
-
if ( k )
-
{
-
printf( "%0o%0o ", s, k )
-
}
-
print
-
}'
-
}
-
-
function lsa {
-
ls -al | awk '{
-
k = 0
-
s = 0
-
for( i = 0; i <= 8; i++ )
-
{
-
k += ( ( substr( $1, i+2, 1 ) ~ /[rwxst]/ ) * 2 ^( 8 - i ) )
-
}
-
j = 4
-
for( i = 4; i <= 10; i += 3 )
-
{
-
s += ( ( substr( $1, i, 1 ) ~ /[stST]/ ) * j )
-
j/=2
-
}
-
if ( k )
-
{
-
printf( "%0o%0o ", s, k )
-
}
-
print
-
}'
-
}
-
Similar but different.
ashitpro,IRYHS !
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sean McIlroy |
last post by:
I recently found out that unicode("\347", "iso-8859-1") is the
lowercase c-with-cedilla, so I set out to round up the unicode numbers
of the extra characters you need for French, and I found them...
|
by: KB |
last post by:
Hi,
This may be a rudimentary question:
How to convert a string like '777' to an octal integer like 0777,
so that it can be used in os.chmod('myfile',0777)?
I know the leading zero is...
|
by: bearophileHUGS |
last post by:
Hello, I have four things to ask or to suggest, sorry if they seem
basic or already discussed.
-------------------
I am still ignorant about Tkinter. This little program, after pressing
the...
|
by: Jim |
last post by:
I need to input a stream of data that is a string. In
that string are some octal numbers. What happen, did you
forget the ushort.Parse(string,...) that accepts octal
numbers? You have decimal...
|
by: fuch6921 |
last post by:
I want to read in an Octal number argument and have it stored as an
octal number. For instance the user will type: ./a.out 777 and it
will store the octal number 777. But it atoi does this as an...
|
by: jaks.maths |
last post by:
How to convert negative integer to hexadecimal or octal number?
Ex: -568
What is the equivalent hexadecimal and octal number??
|
by: Gary Brown |
last post by:
Hi,
I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and authenticity
if these
can be entered in octal. I...
|
by: laurent.pauloin |
last post by:
Hello,
I would like to print a signed octal.
With a signed short it's printf %hi but what about an octal ?
Tk !
|
by: HaifaCarina |
last post by:
Here's the code is used but...but still something is wrong... i need help...
/*CONVERTING DECIMAL TO OCTAL*/
String inputDeci,octal="";
int deci,count=0, i, h;
...
|
by: notahipee |
last post by:
I have been trying to cin an number from 0 to 9 with a leading 0. For
example 00 or 07. I was using a switch case.
switch (int)
{
case 01: break;
case 02: break;.....
My problem arises at 08...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |