File/directory information......


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File/directory information......
# 43  
Old 01-10-2002
Ok, lets clear a few things up. Thx davidl......heres the test results Smilie

echo abcdef | sed -e "s/c/X/" <--should yield--> abXdef
that worked, it printed abXdef, like u said Smilie

--------------------
ls -ld filename |cut -c2-10 <--Should yield--> -rwxr-xr-x
yep, worked excellent Smilie

--------------------
ls -ld somefilename | cut -c2-10 | /usr/bin/tr [-rwx] [0421]
didnt work, printed error message: /usr/bin/tr Bad string. BUT this worked:
ls -ld filenmame | cut -c2-10 | tr '\-rwx' 0421
which printed converted the r's, w's, and x's with numbers e.g 421000000

BUT, I couldn't get any further and get it to print the numerically values with spaces????
# 44  
Old 01-10-2002
Makaveli.2003, try this... Basically the same stuff you've been doing... with a small change in syntax.

echo abcdef |sed 's/cd/GREAT/g' <--Should Display--> abGREATef


echo abcdef |sed 's/./& /g' <Should Display--> a b c d e f
***Be careful when you type this one!!
***Note there are no spaces from 's/./&
and there is ONE space after '&'****

You've probably already looked at that.. just though I'd throw it out anyways Smilie
# 45  
Old 01-10-2002
ls -l menu | cut -c2-10 | tr '\-rwx' 0421 | sed "s/./& /g" | awk '{print $1+$2+$3 $4+$5+$6 $7+$8+$9}'
produces: 7

got it to work, think it was coz i didnt put the space between the "&" and the "/", sorrrrryyyyyy. But shouldnt it print "700"????
# 46  
Old 01-10-2002
The code you just showed should indeed output 3 digits. Make sure that you are executing the code as shown. In earlier posts, you erroneously showed the awk portion as:

awk '{print $1+$2+$3+$4+$5+$6+$7+$8+$9}'
which prints a single sum, instead of
awk '{print $1+$2+$3 $4+$5+$6 $7+$8+$9}'
which prints three sums.

Spaces and punctuation are critical. Once, a missing period in a Fortran program caused a major unmanned rocket launch to crash (really).

First leave off the awk part and try this:

ls -l menu | cut -c2-10 | tr '\-rwx' 0421 | sed "s/./& /g"

That should print 4 2 1 0 0 0 0 0 0
Jimbo
# 47  
Old 01-10-2002
Yep, Jimbo worked a treat.

I just want to thank every1 that has helped: Jimbo, negative, shaik786, sbw1, guest100, Perderabo, davidl, and LivinFree thanx alot Smilie Smilie Smilie Smilie

Especially want to thank Jimbo and davidl, great work and keep it up. Thanx for ur dedication, its really appreciated.

P.S
Quote:
Originally posted by Jimbo
Spaces and punctuation are critical. Once, a missing period in a Fortran program caused a major unmanned rocket launch to crash (really).
Yea, someone told me about that. Again thanx. Smilie Smilie

Last edited by Makaveli.2003; 01-10-2002 at 10:58 PM..
# 48  
Old 01-12-2002
You're welcome, Makaveli. And I hate to add to an already too-long thread, but, I don't like posting a solution that will sometimes give incorrect results. So, I offer my new solution, which should handle all cases including suid and sticky bits. And special thanks to Perderabo for his excellent contribution.

Code:
#!/bin/ksh
ls -ld $* | awk 'BEGIN {
v["r1"]=400; v["w2"]=200; v["x3"]=100; v["s3"]=4100; v["S3"]=4000
v["r4"]=40 ; v["w5"]=20 ; v["x6"]=10 ; v["s6"]=2010; v["S6"]=2000
v["r7"]=4  ; v["w8"]=2  ; v["x9"]=1  ; v["t9"]=1001; v["T9"]=1000}
{val=0
 for (i=1;i<=9;i++) val=val+v[substr($0,i+1,1)i]
 printf "%4d %s\n",val,$NF}'

perms.sh jb*
666 jbdisks
755 jbexp
666 jbfilea
2666 jbll
755 jbtest1
Jimbo
# 49  
Old 02-24-2002
Question

Makaveli.2003,

when you tried echo piped into tr, did you put a single quote around the tests? ie...

echo rwx | tr '[rwx] [421]'

I tried exactly what was posted and received the error no match when I didn't use the single quote, but it worked fine when I used the single quote.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

3. UNIX for Dummies Questions & Answers

How can I use my code to gather information from a file in a completely different directory?

I need my code to compare two different files that are in two completely different directories, How can I do this? So for example, my code will look at file1 which is in my home directory, and compare the files with those from file2 that is in /abc/adf/adr/afc/adf/file2... does that make sense? (1 Reply)
Discussion started by: castrojc
1 Replies

4. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Shell Programming and Scripting

Only the required tag information the XML file file

Hi i have a single line xml file having many account no tag, from which i need only the account no from the tag. any one can help on this. below is the xml file: ... (2 Replies)
Discussion started by: Saravanapk
2 Replies

7. Shell Programming and Scripting

Generating an xml having information related to files in the directory

Hi all, Have to generate an xml having information related to files in the directory Suppose i have file file1.xml (datafile) file2.xml (datafile) file3.xml (metafile) Now i need to generate an xml in the format >> <?xml version="1.0" encoding="UTF-8"?> <AuditFile Version="2.0">... (8 Replies)
Discussion started by: abhinav192
8 Replies

8. UNIX for Dummies Questions & Answers

Read directory and fill a file with this information

Hello All, Got a question to make a script what reads a directory and put the file names from that directory in a file with some extra text. ls /tempdir output is: file1.gfh file2.txt file4.zzz these file names (always with an extention) must be placed in a line and written to... (2 Replies)
Discussion started by: ToXiQ
2 Replies

9. UNIX for Dummies Questions & Answers

why does tar sometimes include directory information?

hi, say I have dirA/file1 dirB/file2 and I tar them up, and then do zcat Tar.tar | tar tvf - Sometimes I will see: dirA/ dirA/file1 dirB/ dirB/file2 yet other times I will see (4 Replies)
Discussion started by: JamesByars
4 Replies

10. UNIX for Dummies Questions & Answers

date information of a directory

when i list the content of a directory date informations are also listed (ls -ltr) for included files and directories. for example: i see the date Jun 29 14:43 for one of the included directory, but when i look into the files contained in this directory i cannot see any file with this... (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies
Login or Register to Ask a Question