The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 03:44 PM
Parse the .txt file for folder name and FTP to the corrsponding folder. MeganP Shell Programming and Scripting 3 07-03-2007 02:54 PM
getting a file name from a folder u263066 Shell Programming and Scripting 4 08-14-2006 12:10 PM
pickup file from folder ram2s2001 Shell Programming and Scripting 0 03-07-2006 02:02 AM
Deleting the file in a folder srivsn Shell Programming and Scripting 2 12-14-2005 09:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2006
u263066 u263066 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 66
file name in folder

here is the few commond i am doing:

Code:
$ ls -l
total 6
drwxrwxr-x   2 dv1gfp   dv1gfp      1024 Oct 12 09:57 archive
-rw-r--r--   1 odv1gfp  oradba      1805 Oct 12 09:56 Schroders.CSV
$ ls -lrt * | awk '{print $9}'|grep -v "^d"
Schroders.CSV



test.dat
SANJIT4.dat
CITI5.dat
ANAND6.dat
ANA8.dat
ANA7.dat
3.dat
2.dat
export.CSV_1
export.CSV
export.csv.orig
$

now i want to know the file name in this folder, but giving this command listing out all files within archive folder also.
Can anyone help me out, which command should I release for this.
  #2 (permalink)  
Old 10-12-2006
Tomato Tomato is offline
Registered User
  
 

Join Date: Sep 2006
Location: HKSAR, China
Posts: 8
What do you want? Do you want to show file but not directory?
If yes, try this


Code:
for file in `ls -lrt * | awk '{print $9}'|grep -v "^d"`
do
    if [ -f $file ]; then
       echo $file
   fi
loop

  #3 (permalink)  
Old 10-12-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
ls -lrt | grep -v "^d" | awk '{print $9}'


remove * from ls command and shift grep one step ahead... because if you put awk first, it takes only the 9 th column ( i.e file name )... then no where you can find "^d" to remove lines.
  #4 (permalink)  
Old 10-12-2006
u263066 u263066 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 66
hi


Code:
$ ls -lrt | grep -v "^d" | awk '{print $9}'

Sanjit.CSV

Why there is one blank line coming here

where as line

Code:
$ ls -lrt *.CSV | awk '{print $9}'|grep -v "^d"
sanjit.CSV

no blank line coming
  #5 (permalink)  
Old 10-12-2006
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2005
Location: London
Posts: 222
Just try... the following two commands

ls -lrt *.CSV
ls -lrt

In the second command you will find additional line something like "total 6"... this is causing the blank line...

if you want to filter this out, add

change the grep to

egrep -v "^d|^total"
  #6 (permalink)  
Old 10-12-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
Quote:
Originally Posted by Tomato
What do you want? Do you want to show file but not directory?
If yes, try this


Code:
for file in `ls -lrt * | awk '{print $9}'|grep -v "^d"`
do
    if [ -f $file ]; then
       echo $file
   fi
loop

Code:
#!/bin/sh

find -type f | while IFS= read vo
do
echo `basename "$vo"`
done

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0