Store the files details in different file using bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store the files details in different file using bash
# 1  
Old 03-20-2011
Store the files details in different file using bash

Hi all,

this is output of ls command !!

there is differen different files permission are there , and my requirement is each file permission is stored in different different file.
Code:
rwxr-xr-x  1 root root       0 Mar 29  2011 2
-rwxr-xr-x  1 root root       0 Mar 29  2011 20
drwxr-xr-x  2 root root    4096 Mar 16 23:12 a
-rwxr-xr-x  1 root root    1050 Mar 16 08:06 anaconda-ks.cfg
drwxr-xr-x  2 root root    4096 Mar 29  2011 anish
drwxr-xr-x  2 root root    4096 Mar 19 05:36 av
-rw-r--r--  1 root root  854994 Oct 25 18:39 boss.tgz
drwxr-xr-x  2 root root    4096 Mar 16 23:12 c
drwxr-xr-x  6 root root    4096 Mar 25  2011 del
drwxr-xr-x  6 root root    4096 Mar 20 14:59 Desktop
-rwxr-xr-x  1 root root 1141195 Mar  9 15:27 disketa-tim.tgz
-rwxr-xr-x  1 root root       0 Jan 16 00:00 dummy
drwxr-xr-x  2 root root    4096 Mar 16 23:12 e
drwxr-xr-x  2 root root    4096 Mar 17 00:10 flo
-rwxr-xr-x  1 root root      54 Mar 20 15:35 for.sh
drwxr-xr-x  2 root root    4096 Mar 16 23:12 gfg
-rwxr-xr-x  1 root root   30632 Mar 16 08:06 install.log
-rwxr-xr-x  1 root root    4492 Mar 16 08:03 install.log.syslog
-rw-r--r--  1 root root       0 Mar 19 23:16 logfile.txt
-rw-r--r--  1 root root       0 Mar 20 15:37 ls.txt
-rw-------  1 root root   17215 Mar 20 01:38 mbox
drwxr-xr-x  2 root root    4096 Mar 20 15:09 scripts
-rwxr-xr-x  1 root root   38946 Mar 16 08:12 scsconfig.log
-rwxr-xr-x  1 root root     195 Mar 16 08:12 scsrun.log
drwxr-xr-x 20 root root    4096 Mar 18 08:01 uat
drwxr-xr-x  2 root root    4096 Mar 16 23:12 w1


like this.

Code:
output :

file 1:
rwxr-xr-x  1 root root       0 Mar 29  2011 2


file 2:
drwxr-xr-x  2 root root    4096 Mar 16 23:12 e
drwxr-xr-x  2 root root    4096 Mar 17 00:10 flo
drwxr-xr-x  2 root root    4096 Mar 16 23:12 c
drwxr-xr-x  6 root root    4096 Mar 25  2011 del


file 3:

-rwxr-xr-x  1 root root   38946 Mar 16 08:12 scsconfig.log
-rwxr-xr-x  1 root root     195 Mar 16 08:12 scsrun.log

file 4:

-rw-------  1 root root   17215 Mar 20 01:38 mbox

file 5:

-rw-r--r--  1 root root       0 Mar 19 23:16 logfile.txt
-rw-r--r--  1 root root       0 Mar 20 15:37 ls.txt


how is it possible using shell scripting , please guide me


With Regards
Anish Kumar.V

Last edited by Scott; 03-20-2011 at 07:37 AM.. Reason: Replace Quote tags with Code tags
# 2  
Old 03-20-2011
Code:
#!/bin/bash
ls -l |\
while read line
do
        case ${line%% *} in
                 rwxr-xr-x)     echo "$line" >> file1;;
                drwxr-xr-x)     echo "$line" >> file2;;
                -rwxr-xr-x)     echo "$line" >> file3;;
                -rw-------)     echo "$line" >> file4;;
                -rw-r--r--)     echo "$line" >> file5;;
        esac
done

# 3  
Old 03-20-2011
Code:
Code:
sort inputfile | awk '{if($1!=a){a=$1;print $0 >"file_"++i}else{a=$1;print $0>>"file_"i}}'

This User Gave Thanks to pravin27 For This Post:
# 4  
Old 03-20-2011
Hi all,

Thanks for your replies !!! it works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to match and store line as variable

The bash below loops through a specific directory dir and finds and writes the oldest folder to a variable called $filename. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Bash to store result in variable for other lines in script to use

I can not figure out how to capture the $filename variable store by the bash. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find "$dir" -maxdepth 1 -mindepth 1 -type d -printf... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

Store filenames for wget in bash

I have a bash that downloads a list of files as a text file using wget. What I now need to do is store those files names and pass them to a download call also using wget. List.txt in /home directory FilterDuplicates.html file1.bam file2.bam file3.bam file1.vcf.gz file2.vcf.gz... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

5. Shell Programming and Scripting

Execute sequential files and store data in single file

1)In a particualr path i have a set of inputfiles like path:/defaultmis/MonthlyLoads/INFA_EXPORT_022013/map* example: 1)map_de 2)map_cod 3)map_feg ........and so on in above path there wil be nearly 15 to 20 files starting with map and in other path i have another file input file... (4 Replies)
Discussion started by: katakamvivek
4 Replies

6. UNIX for Dummies Questions & Answers

at -l doesnt give details of the scheduled job. How to get the details?

I have scheduled couple of shell scripts to run using 'at' command. The o/p of at -l is: $ at -l 1320904800.a Thu Nov 10 01:00:00 2011 1320894000.a Wed Nov 9 22:00:00 2011 1320876000.a Wed Nov 9 17:00:00 2011 $ uname -a SunOS dc2prcrptetl2 5.9 Generic_122300-54 sun4u sparc... (2 Replies)
Discussion started by: superparticle
2 Replies

7. Shell Programming and Scripting

to read two files, search for patterns and store the output in third file

hello i have two files temp.txt and temp_unique.text the second file consists the unique fields from the temp.txt file the strings stored are in the following form 4,4 17,12 15,65 4,4 14,41 15,65 65,89 1254,1298i'm able to run the following script to get the total count of a... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

8. Shell Programming and Scripting

Find diff bet 2 files and store result in another file

Hi I want to compare 2 files. The files have the same amount of rows and columns. So each line must be compare against the other and if one differs from the other, the result of both must be stored in a seperate file. I am doing this in awk. Here is my file1: Blocks... (2 Replies)
Discussion started by: ladyAnne
2 Replies

9. Shell Programming and Scripting

Most reliable way to store file contents in an array in bash

Hi Guys, I have a file which has numbers in it separated by newlines as follows: 1.113 1.456 0.556 0.021 -0.541 -0.444 I am using the following code to store these in an array in bash: FILE14=data.txt ARRAY14=(`awk '{print}' $FILE14`) (6 Replies)
Discussion started by: npatwardhan
6 Replies

10. Web Development

store images into databases or path to file system files ?

hi, I need a quick information about storing images into mysql databases. Is more convenient to store a path to the filesystem folder in which the images are stored, or is possible to directly store the images into my tables ? thanks (2 Replies)
Discussion started by: aneuryzma
2 Replies
Login or Register to Ask a Question