Sponsored Content
Top Forums Shell Programming and Scripting How to store files names from a directory to an array Post 302523061 by mirni on Tuesday 17th of May 2011 06:17:37 PM
Old 05-17-2011
What shell are you using?

This construct is fishy:
Quote:
ls -l *.log | set -A arr_Filenames $(awk '{print $9}')
That awk statement is out of place -- did you want to estract 9th column from ls output? Why do you use -l option then at all?
Try this:
Code:
arr_Filenames=(`ls *.log`)

or, if you really want to filter the output of ls command:
Code:
arr_Filenames=(`ls -l *.log | awk 'someAwkCommandHere'`)

The var=() construct will make 'var' an array. (In Bash, at least)

You can also assign into array in a following way:
Code:
$ ls -l  *log 
-rw-rw-r-- 1 user group  23230 May 17 10:19 Changelog
-rw-rw-r-- 1 user group 145060 May 17 12:01 config.log
$ ls -l  *log | while read -a arr ; do 
  echo "perms=${arr[0]} ; size=${arr[4]}" ;
done
perms=-rw-rw-r-- ; size=23230
perms=-rw-rw-r-- ; size=145060

Which will read each line of input being piped in into an array (-a switch of built-in read).
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting all the files modified today & store the names in a variable as , separated

Hi all, I have a question. I have a folder. I want to find the list of files that are modified today and store all those file names in a variable as comma separated values. I thought of using "find . -mtime 0" command to find the list of files modified today. Also to get those values of file... (10 Replies)
Discussion started by: ananthi_ku
10 Replies

2. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

3. Shell Programming and Scripting

bash Script: Issue with iterating Directory and store into array

Hi all, I am working on a backup based script, in which it enters to a directory and check the sub-directories and copy the names into an array. cd $CPFs k=0 for i in * do if then ARRs="$i" k=$(($k+1)) #echo "$i" ... (19 Replies)
Discussion started by: canishk
19 Replies

4. Shell Programming and Scripting

how can i copy a list of files with different names into others directory have the same name

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (0 Replies)
Discussion started by: t17
0 Replies

5. Shell Programming and Scripting

renaming files from an array of names

I haven’t used Unix in over 25 years … and so I am at a loss for something that should be very simple. I have a lot of jpeg files (i.jpg) of students in a yearbook.. I also have an array name(i) of their names. I need to rename each “i.jpg” to “name(i).jpg”. I believe the ksh script... (11 Replies)
Discussion started by: chuckmg
11 Replies

6. Shell Programming and Scripting

What amount of store occupy only files in a directory?

Hello I'm trying to do an exercise programming in bash where I have to get only the store of files in a directory but NOT all capacity of the directory. I probe with: du -sh "$directory"*` but I get all the capacity and I probe with ls command but I couldnt. Are there any way to get only files... (2 Replies)
Discussion started by: adiegorpc
2 Replies

7. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

8. Shell Programming and Scripting

Edit names of files in a directory

Hi all, I have a directory with multiple (thousnads) of files, which are named this way ABCDEF.wo.im-1 OKRAME.ire.roi IOJEAFO01.irt.gfg IMNYBL05.REG.gkf I would like to keep the part of the name (everything before the first dot in the filename). The desired output: ABCDEF... (3 Replies)
Discussion started by: Error404
3 Replies

9. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies
console.perms(5)					   System Administrator's Manual					  console.perms(5)

NAME
console.perms - permissions control file for users at the system console DESCRIPTION
/etc/security/console.perms and .perms files in the /etc/security/console.perms.d directory determine the permissions that will be given to priviledged users of the console at login time, and the permissions to which to revert when the users log out. They are read by the pam_console_apply helper executable. The format is: <class>=space-separated list of words login-regexp|<login-class> perm dev-glob|<dev-class> revert-mode revert-owner[.revert-group] The revert-mode, revert-owner, and revert-group fields are optional, and default to 0600, root, and root, respectively. The words in a class definition are evaluated as globs if they refer to files, but as regular expressions if they apply to a console defi- nition. Do not mix them. Any line can be broken and continued on the next line by using a character as the last character on the line. The login-class class and the login-regexp word are evaluated as regular expressions. The dev-class and the dev-glob word are evaluated as shell-style globs. If a name given corresponds to a directory, and if it is a mount point listed in /etc/fstab, the device node associated with the filesystem mounted at that point will be substituted in its place. Classes are denoted by being contained in < angle bracket > characters; a lack of < angle brackets > indicates that the string is to be taken literally as a login-regexp or a dev-glob, depending on its input position. SEE ALSO
pam_console(8) pam_console_apply(8) console.apps(5) AUTHOR
Michael K. Johnson <johnsonm@redhat.com> Red Hat Software 2005/5/2 console.perms(5)
All times are GMT -4. The time now is 03:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy