ls command format display


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls command format display
# 1  
Old 04-22-2009
ls command format display

Hi I have 3 files
[osbadmin@qa1 cp]$ ls -l
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1)

I need to see this
"SANITY_TEST" "Success 123333" "Success 123333 (1)"
that means I have to use this as array elements as
arr=("SANITY_TEST" "Success 123333" "Success 123333 (1)")

Please help me.
Thanks in advance
# 2  
Old 04-22-2009
Try this:

Code:
val="\"";
ls -ltr | awk -v var=$val  '{ORS=" ";print var $NF var; }'

# 3  
Old 04-22-2009
it's not working plz hlp

Quote:
Originally Posted by dennis.jacob
Try this:

Code:
val="\"";
ls -ltr | awk -v var=$val  '{ORS=" ";print var $NF var; }'



Hi
When I tried this command on

[osbadmin@qa1 cp]$ ll
total 1272
-rw-rw-r-- 1 osbadmin osbadmin 0 Apr 22 14:38 a b
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1)
[osbadmin@qa1 cp]$
it gives

[osbadmin@qa1 cp]$ val="\""; ls -ltr | awk -v var=$val '{ORS=" ";print var $NF var; }'
"1272" "(1)" "123333" "SANITY_TEST" "b" [osbadmin@qa1 cp]$

I have to get output as "a b" "SANITY_TEST" "Success 123333" "Success 123333 (1)"

Please help me.........
# 4  
Old 04-22-2009
Quote:
Originally Posted by mnmonu
Hi
When I tried this command on

[osbadmin@qa1 cp]$ ll
total 1272
-rw-rw-r-- 1 osbadmin osbadmin 0 Apr 22 14:38 a b
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333
-rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1)
[osbadmin@qa1 cp]$
it gives

[osbadmin@qa1 cp]$ val="\""; ls -ltr | awk -v var=$val '{ORS=" ";print var $NF var; }'
"1272" "(1)" "123333" "SANITY_TEST" "b" [osbadmin@qa1 cp]$

I have to get output as "a b" "SANITY_TEST" "Success 123333" "Success 123333 (1)"

Please help me.........
Try this:

Code:
ls -ltr | sed '/^-/!d'  |  sed 's/\(.*\):\([0-9]*\) \(.*\)/\"\3\"/' | tr "\n" " "

# 5  
Old 04-22-2009
Fill array

With ksh:

Code:
set -A arr $(ls)

Or:

Code:
ls | while read file
do
 i=$(($i+1))
 arr[i]="$file"
done

Regards
# 6  
Old 04-22-2009
Its absolutely helpful

Quote:
Originally Posted by dennis.jacob
Try this:

Code:
ls -ltr | sed '/^-/!d'  |  sed 's/\(.*\):\([0-9]*\) \(.*\)/\"\3\"/' | tr "\n" " "


Thanks this works properly...........................
Thanks again.
# 7  
Old 04-22-2009
Quote:
Originally Posted by Franklin52
With ksh:

Code:
set -A arr $(ls)

Or:

Code:
ls | while read file
do
 i=$(($i+1))
 arr[i]="$file"
done

Regards
It also works well.........
Thaks for your support..............
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Display time in 12 hr format

Write a script named time that displays the time in standard 12-hour format, rather than 24-hour format. Allow the user to give a -m option to get 24-hour format. For example: > date Sun Feb 10 10:56:50 CST 2008 > time 10:56 AM > date Sun Feb 10 21:57:07 CST 2008 > time 9:57 PM >... (0 Replies)
Discussion started by: satish24
0 Replies

2. UNIX for Beginners Questions & Answers

Hour display format

Hello Sir/Madam, I'm using Putty utility to run a shell script. I found HOUR display in two positions in UNIX. Is it possible to display in four positions? File name example: my file name is: HourlyData_20160708_1400.txt I'm in the process of comparing current date and time with the file... (15 Replies)
Discussion started by: V1l1h1
15 Replies

3. Shell Programming and Scripting

Hange display format

I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" . #vi file1 this is testing file A aaaaa B bbbbb A ccccc B ddddd A eeeee B fffff A ggggg B hhhhh I would like to have a script to use the... (3 Replies)
Discussion started by: ust3
3 Replies

4. Homework & Coursework Questions

How to display in column format?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I would like to know how to display my output to this format below: 5000 Bash 300 zsh 0 sh ... (4 Replies)
Discussion started by: scopiop
4 Replies

5. Shell Programming and Scripting

Display date in mm/dd/yy format in sed command

Hi All, Following is my issue. $MAIL_DOC = test.txt test.txt contains the following text . This process was executed in the %INSTANCE% instance on %RUNDATE%. I am trying to execute the following script var=`echo $ORACLE_SID | tr ` NOW=$(date +"%D") sed -e... (3 Replies)
Discussion started by: megha2525
3 Replies

6. Emergency UNIX and Linux Support

Change the display format for ls -l command in AIX

Hi, I am using AIX 5.3. In my server if I list the file , I got the below result in below format. ********************************************* -rw-rw--w- 1 letapp1 staff 0 Jun 8 02:53 CC00030710.cntrl ********************************************* But now I am seeing... (22 Replies)
Discussion started by: puni
22 Replies

7. UNIX for Dummies Questions & Answers

Date format Display Help

I have tried various arguments to get the date display as "Mar 10". I have tried date +"%c" -------> Wed Mar 10 11:51:21 EST 2010 date +"%b%d%Y_%H%M%S" --------> Mar102010_115121 date +"%b%d" -------> Mar10 date +"%t%b%e" ... (3 Replies)
Discussion started by: moveaix
3 Replies

8. UNIX for Advanced & Expert Users

Need to display complete format of ps

Hi All, For one of my script I need to get the complete format of PS as result. Actually in our application, we have to execute some program to get the data for batch files. Now there is some java script is running on unix for this which is not identifiable. I want to know how to... (2 Replies)
Discussion started by: nishank.jain
2 Replies

9. UNIX for Dummies Questions & Answers

Date Display Format

Hello People, How can I display the date in a continuous format along with the time as below : 20091001_154547 i.e yyyymmdd_hhmmss format. Thanks. (3 Replies)
Discussion started by: sushant172
3 Replies

10. UNIX for Advanced & Expert Users

ls -l timestamp display format

The time stamp format using "ls -l" is either mmm dd hh:mm or mmm dd yyyy. For later case, how can I know the hh:mm as well. Thanks. (3 Replies)
Discussion started by: pok.fung
3 Replies
Login or Register to Ask a Question