plz help normal doubt abt shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting plz help normal doubt abt shell script
# 1  
Old 09-23-2010
plz help normal doubt abt shell script

How to print a only files and not directories in a path.
for exam :a user consists both files and directoris in his path.
i have to write a script to display only files not dirctories.
and only dirctories not files.

Advance thanks to forum members.Smilie
# 2  
Old 09-23-2010
for only file use
Code:
ls -l|awk '/^-/{print $NF}'

For only directory name
Code:
ls -l|awk '/^d/{print $NF}'
ls -d */


Last edited by posix; 09-23-2010 at 06:34 AM.. Reason: Missed some code
# 3  
Old 09-23-2010
Bug thanks for quick reply-can

hi thanks for reply friend.
can u say one more?
how to print paticular column from a text file.
for exm:
-rw-r----- 1 sranga staff 21 Sep 15 22:32 examp.sh
-rw-r----- 1 sranga staff 218 Sep 16 22:27 file.sh
-rw-r----- 1 sranga staff 0 Sep 23 00:27 file.txt

i have to print only second column from file disp.txt
thanks for quick reply.I am looking forward from uSmilie
# 4  
Old 09-23-2010
you can use awk or cut command
Code:
awk '{print $2}' disp.txt

use cut with suitable option i mean as per your file delimiter
Code:
ls -l |cut -d' ' -f2

For other fields change the numeric values .
# 5  
Old 09-23-2010
please, do not use ls -l to parse for file names!. Use find, or the shell. !
Code:
find /path -type f 
find /path -type d

Code:
for myfiles in *
do
  [ -d "$myfiles" ] && echo "directory"
  .........
done

# 6  
Old 09-23-2010
Quote:
Originally Posted by sivaranga001
How to print a only files and not directories in a path.
for exam :a user consists both files and directoris in his path.
i have to write a script to display only files not dirctories.
and only dirctories not files.

Advance thanks to forum members.Smilie
Code:
ls -l |grep -v ^d

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Clarify doubt ... plz Urgent

Hi friends, I am new to UNIX. I going to transfer files using SFTP. I am writing a script and using mget . If i am using mget * means, if all the files and their sub directories are transferred or not? If suppose , the local system dose not have the sub directory then what will... (1 Reply)
Discussion started by: punitha
1 Replies

2. IP Networking

abt IP_ADD to DNS-- Plz help me:ASAP

Hello to forum memebers, Please help for below querry. I am new n/w programming ,I wan to know abt the how to change IP to Domain name thorugh Shell script. I am looking for ur reply. Plz......... advance thanks to Forum.:) (2 Replies)
Discussion started by: sivaranga001
2 Replies

3. Shell Programming and Scripting

i'm new to shell can handle this script for me plz

Write a shell script named displayargs that prints FOUR lines. The first line tells the name that was used to invoke the script, the second line tells how many parameters there were, the third line tells what the last parameter was, and the fourth line tells what the first parameter was. For... (8 Replies)
Discussion started by: kedah160
8 Replies

4. Shell Programming and Scripting

Normal exit from shell script

How to do a normal exit from .SH program (1 Reply)
Discussion started by: 1manraj1
1 Replies

5. UNIX for Dummies Questions & Answers

Shell Script Help Plz

####################################################################### # #This script will perform the menu such as : list file, change catalog, #file check, # #This script was written in UNIX Shell Programming Language #... (3 Replies)
Discussion started by: shekhani
3 Replies

6. Shell Programming and Scripting

Plz correct my syntax of shell script

Dear all I am still bit new in shell script area.I am writing down a shell script which I guess somewhere wrong so please kindly correct it. I would be greatful for that. What I actually want from this shell script is that it will move all the files one by one to another server which can be... (2 Replies)
Discussion started by: girish.batra
2 Replies

7. Shell Programming and Scripting

shell script to call other files..plz help

Hi all, I have a number of shell script,perl script.. etc in a directory,which i need to execute in some order.Now i need to create a script to call all these files in that order..so that the new script will execute all the files one by one....plz help this is urgent. Thanks In advance Anju (3 Replies)
Discussion started by: anju
3 Replies

8. Shell Programming and Scripting

plz help me by creating required shell script

Dear all I am new to shell script. And this is my first post to this site as well as this forum. I would like to tell this forum that I require shell script, which is regarding transfers of files from a specific directory in a server A to server B on a specific directory through sftp command.... (5 Replies)
Discussion started by: girish.batra
5 Replies

9. Shell Programming and Scripting

shell script doubt

Hi, While reading a shell script ,i have come accross the following statements. script_name_full=$0 ***script_name=${script_name_full##*\} ***script_name_noexst=${script_name%%\.ksh} host_name=`hostname` ***host_name_short=${host_name%%\.*} can anybody tell me what is the purpose of marked... (5 Replies)
Discussion started by: ravi raj kumar
5 Replies

10. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question