Formatting of output from awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting of output from awk
# 1  
Old 07-21-2011
Formatting of output from awk

Hi;
i m running an command like;
Code:
getfacl $(find /home/fstl/testShell/ -type f -ls | awk '{print $11}')

and i m getting outpiut for all files in "testShell" folder as;
Code:
# file: home/fstl/testShell/.script1.sh.swp
# owner: root
# group: root
user:fstl:rw-
user:ajay:rw-
group:root:r--
group:bhavani:r--


# file: home/fstl/testShell/test
# owner: fstl
# group: fstl
user:fstl:rw-
user:ajay:rw-
group:root:r--
group:bhavani:r--

supposing der are only 2 files;

but i want to get formatted output like;
Code:
filepath:home/fstl/testShell/test
users:fstl,ajay
permissions for users:rw-,rw-
groups:root,bhavani
permissions for groups:r--,r--


for all the files;

is der nay way one can do this using awk, stroing variables or nething
please help me out;

thnks;
Ajay

Last edited by Franklin52; 07-21-2011 at 04:04 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-22-2011
Yes,
add this at the end of your pipeline:

Code:
awk -F: 'END { puts( ) }
/^# file:/ {
  if ( f ) puts( )
  sub( /^# file: /, x )
  f = $0; u = up = g = gp = x
  }
/^user:/ {  
  u = u ? u "," $2 : "users" FS $2
  up = up ? up "," $3 : "permissions for users" FS $3
  }
/^group:/ {
  g = g ? g "," $2 : "groups:" $2
  gp = gp ? gp "," $3 : "permissions for groups" FS $3
  }
func puts( ) {  
  print "filepath:" f
  print u; print up
  print g; print gp
  print x
  }' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output formatting

Hi , can anyone help me in this Input file Name= XYZ Company= ALPHA City= Stockhomn Equipment=computer Country=Sweden Name=MNC Company=Beta City=Kaulampur Equipment=computer Country=Malaysia Name=JVC Company=gamma City=Kiruna (3 Replies)
Discussion started by: swets
3 Replies

2. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies

3. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

4. Shell Programming and Scripting

Formatting output using awk in ksh

:oi was trying to write a script to format output of a command in ksh which has output as below: so i used : to get which i require at all times. But problem occurs when status part changes. above output i get when status is SU (success).If the status is IN (inactive), output of... (1 Reply)
Discussion started by: pr5439
1 Replies

5. Shell Programming and Scripting

Formatting grep and awk output

Hi there. I have a very large file and I am trying to format it so that I can pull out certain pieces of data/info and report it in spreadsheet format/style. The file has ###### which will separate each line that will be listed in the spreadsheet. Whenever I find "No" at the end of a line I want... (7 Replies)
Discussion started by: kieranfoley
7 Replies

6. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

7. Shell Programming and Scripting

output formatting with awk.

# echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin How would i write a script to display permission on each folders in $PATH variable below format. drwxr-xr-x 2 0 root 4096 Nov 24 14:51 /usr/kerberos/sbin drwxr-xr-x 2 0... (2 Replies)
Discussion started by: pinga123
2 Replies

8. Shell Programming and Scripting

formatting the output

Is it possible to convert the attached file to the format mentioned. Here for a particular job the table name and the corresponding instance name from one test run "X" is compared with the table name and the instance name from the second test run "Y" for output rows,affected rows,applied... (1 Reply)
Discussion started by: ragavhere
1 Replies

9. Shell Programming and Scripting

Question about formatting output using AWK

Hi everyone. I've got this fille... 0 5000001 5000002 5000003 5000006 5000007 5000219 11000156 11003130 11003132and this script... #!/bin/ksh FILE_ALERT_CONTACT_LIST=users.txt userID=`awk -F"=" '{printf $1 ", "}' $FILE_ALERT_CONTACT_LIST` (9 Replies)
Discussion started by: Fatbob
9 Replies

10. Shell Programming and Scripting

Formatting output

Hi, I am new to shell scripting, I ahve written a shell script which would extract me data, but my problem is I want to add a column name to my output. Using grep and sed I am getting my data from the input file. Sample data name : eric name : tom name : sean My output using grep and sed... (3 Replies)
Discussion started by: illur81
3 Replies
Login or Register to Ask a Question

Featured Tech Videos