Need to display the output of ls -l selected columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to display the output of ls -l selected columns
# 1  
Old 06-18-2010
Need to display the output of ls -l selected columns

Hello Friends,

Hope you are doing well.

I am writing a shell script to find out the log file which are not updated in last 1 hours. I've almost completed the script but need your help in formatting its outputs.

Currently, the output of the script is like this(as a flat row):

-rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log

In this the domain name is ICCIR2Test11, log file would be *.log and time would be its modification time as usual.

I need to convert the output as below:

Domain Name Log File Time last updated

ICCIR2Test11 ApplicationManagement.log Jun 18 10:01

I tried the below codes just for a test,
Code:
echo -rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log | cut -d"/" -f6; echo -rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log | cut -d" " -f5,6,7

and the output is

ICCIR2Test11
Jun 18 10:01

Can you please let me know if it is possible to convert it into the format described above?

Any help would be highly appereciated.

Thanks,
Chandan
# 2  
Old 06-18-2010
If your directory location is fixed and always same;

try:
Code:
your script | awk -F '[ /]' '{print $13,$15,$5,$6,$7}'

If your path may vary, and can go beyond the current directory, please let us know.
# 3  
Old 06-18-2010
Thanks a ton Chanchal!!!!!

The awk statement works perfectly and my currently directory path will always remain the same.

Have a great weekend..
# 4  
Old 06-18-2010
For exa
Code:
# cat yourscript
echo "-rw-rw-r-- 1 tibco tibco Jun 18 10:01 /opt/tibco/tra/domain/ICCIR2Test11/logs/ApplicationManagement.log"

Code:
# ./yourscript | ./cutit
Jun 18 10:01 ICCIR2Test11 ApplicationManagement.log

Code:
# cat cutit
#!/bin/bash
file=$1
a=0;i=0
for part in `cat $file`
do
((i++))
if [ $i = 5 ] || [ $i = 6 ] || [ $i = 7 ] ; then
tmp[a]=$part
((a++))
fi
if [ $i = 8 ] ; then
domain=$(echo $part | cut -d'/' -f6)
logfile=$(echo $part | cut -d'/' -f8)
fi
done
echo ${tmp[@]} $domain $logfile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is it possible to ascend a numbers based on selected columns?

I have to ascend the number of two selected columns by horizontal manner. For example, I have a data like this in csv file (tab delimited format) 08 1 19185 18010 16 4 7960 9339 01 6 516769 517428 09 9 51384 49270 I need to ascend the two columns numbers (horizontal manner) like as... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. Shell Programming and Scripting

To display the selected part in text file of unix

0400903071220312 20120322 20:21 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS 182644 000C2 8122011 0000 000 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS ... (6 Replies)
Discussion started by: rammm
6 Replies

3. Shell Programming and Scripting

transpose selected columns

Can I transform input like the below ? Note: Insert zeros if there is no value to transform. Input key name score key1 abc 10 key2 abc 20 key1 xxx 100 key2 xxx 20 key1 zzz 0 key2 zzz 29 key3 zzz 129 key1 yyy 39output abc ... (1 Reply)
Discussion started by: quincyjones
1 Replies

4. Shell Programming and Scripting

compare two files, selected columns only

hi! i have two files that looks like this file 1: ABS 123 456 BCDG 124 542 FGD 459 762 file 2: ABS 132 456 FGD 459 762 output would be: from file1: ABS 132 456 BCDG 124 542 from file 2: ABS 132 456 (4 Replies)
Discussion started by: kingpeejay
4 Replies

5. Shell Programming and Scripting

copying selected records from two columns to another file

Hey guys I have got a tab-separated file and I want to copy only selected records from two columns at a time satisfying specified condition, and create a new file. My tab separated file is like this ID score ID score ID Score ID score ID score 1_11 0.80 2_23 0.74 2.36 0.78 2_34 0.75 A_34... (9 Replies)
Discussion started by: jacks
9 Replies

6. Shell Programming and Scripting

Display output as columns using grep/awk/sed

I have several files with say something like cat sparrow I can grep for "cat" and "sparrow" and usually the output is one below the other cat sparrow How can I view these as columns say Pets Birds cat sparrow Would be great if this can be on command line using awk or... (1 Reply)
Discussion started by: gubbu
1 Replies

7. UNIX for Dummies Questions & Answers

Getting rid of selected columns

Hi All, I've got a file like this: a 1 0 0 0 1 0 0 1 1 3 3 1 4 4 4 b 1 0 0 0 1 4 4 1 3 1 1 4 4 2 2 c 1 0 0 0 2 0 0 3 3 1 3 1 1 2 4 d 1 0 0 0 2 0 0 1 1 0 0 4 4 2 4 The file has ~4200 entries. I need to exclude those columns that are zeros for all those rows that have 2 in column 6. For... (0 Replies)
Discussion started by: zajtat
0 Replies

8. Shell Programming and Scripting

display log at selected locations

Hello all I have a question on displaying log When i am redirecting the output to a log, it displays but in a format which i am not happy about. Can i give any explicit commands which says to display the above log at specific row and column I want to do this for each line of the log What is... (2 Replies)
Discussion started by: vasuarjula
2 Replies

9. UNIX for Dummies Questions & Answers

selected columns exctract

Hi all, I have 50 columns are there, want to exctract 9 columns only.These are not there in sequence. How can i do it. (2 Replies)
Discussion started by: ashokkumar83
2 Replies
Login or Register to Ask a Question

Featured Tech Videos