LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-20-2011, 06:40 AM   #1
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Rep: Reputation: 10
store the files details in different different file using bash


Hi all,

this is output of ls command !!

there is different different files permission are there , and my requirement is each file permission is stored in different different file.

Quote:
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.



Quote:
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
 
Old 03-20-2011, 06:51 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

It is possible to do this with Bash but like all other requests for scripts, you'll have to put in some work yourself first and show us what you've got. Some pointers, use ls -al, followed by sort to order the output, write that to a file, process the file using sed/awk and save the results to other files. That's one way you can use. If you're new to Linux and Bash I suggest you read some tutorials. Here are my two favorites:
Bash Guide for Beginners
Advanced Bash Scripting Guide

Kind regards,

Eric
 
Old 03-20-2011, 07:20 AM   #3
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi EricTRA,

Thanks For your Valuable suggestion!!!!

sort inputfile | awk '{if($1!=a){a=$1;print $0 >"file_"++i}else{a=$1;print $0>>"file_"i}}'

it works!!! using sort and awk command!!!



Thanks and Regards
Anish Kumar.V
 
1 members found this post helpful.
Old 03-20-2011, 07:22 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hi,

There you go, see you can do it!

Kind regards,

Eric

Last edited by EricTRA; 03-20-2011 at 07:22 AM. Reason: You already marked as solved. Thanks.
 
Old 03-20-2011, 10:44 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Just to keep your learning going, here is an alternative (nice thing about awk is being sorted is not necessary):
Code:
awk '!($1 in _){_[$1]="file_"++i}{print >> _[$1]}' inputfile
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Store user input in a config file GUI for a BASH script vaniaspeedy Linux - General 1 12-05-2010 01:08 AM
How to create new log file to store details of the accessed files..! hsatish Linux - Newbie 6 01-22-2009 01:22 AM
File server setup...what directory to store shared files glenn69 Linux - Server 1 07-08-2008 04:42 PM
Store into a file the list of executable files of a system directory jianelisj Linux - Newbie 3 03-17-2008 01:26 PM
Red Hat - VSFTP Server - release of large files to the file store houmb17 Linux - General 4 02-29-2008 06:02 AM


All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration