file name without any space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file name without any space
# 1  
Old 08-15-2006
file name without any space

I have one function which will find the name of filename in the respective folder.I want to capture only the file name , is there any way to restrict only
those name.


Code:
getfilename()
{
#cd $DATDIR
v_file=`ls -lrt *.dat | awk '{print $9}'|grep -v "^d"`
echo $v_file
}

The problem here is that when I pass this v_file as parameter , there are some other space char is going ..thus does not allow to do unix operation through shell script.


assume
there is always one file in the folder like
"test.dat"

then it should be return only test.dat, not any other charcter.
similaly "export.dat" can return only export.dat

I think is there any way to not pass any other char other than name.

I have use cut after grep but no luck.
Code:
ls -lrt *.dat | awk '{print $9}'|grep -v "^d"|cut -c55-120

can anyone advice
thanks in advance
# 2  
Old 08-15-2006
# 3  
Old 08-15-2006
Try basename:
Code:
One example:
admin@unix1:/home/admin$a=$PWD
admin@unix1:/home/admin$echo $a
/home/admin
admin@unix1:/home/admin$echo `basename $a`
admin

# 4  
Old 08-15-2006
thanks it was great help

thanks ...it was great help
# 5  
Old 08-15-2006
Your script does'nt ignore directories because your frep command is misplaced :
Code:
getfilename()
{
#cd $DATDIR
v_file=`ls -lrt *.dat | grep -v "^d| awk '{print $9}'"`
echo $v_file
}

or
Code:
getfilename()
{
#cd $DATDIR
v_file=`ls -lrt *.dat | awk '$0 !~ /^d/ {print $9}'"`
echo $v_file
}

you can also include the basename logic into the awk script :
Code:
getfilename()
{
#cd $DATDIR
v_file=`ls -lrt *.dat | awk '$0 !~ /^d/ {gsub(/.*\//,"",$9) ;print $9}'"`
echo $v_file
}

Jean-Pierre.
# 6  
Old 08-15-2006
whats wrong in the code

could you please verify whats wrong in the first command....

Code:
anands (A) $ ls -lrt *.trn | awk '$0 !~ /^d/ {gsub(/.*\//,"",$9) ;print $9}'

awk: syntax error near line 1
awk: illegal statement near line 1
Code:
anands (A) $ ls -lrt *.trn | awk '$0 !~ /^d/ {print $9}'

citi10082006.trn
citi10082006A.trn
citi11082006.trn
citi14082006.trn
citi15082006_1.trn
Code:
anands (A) $

# 7  
Old 08-16-2006
The command works fine on my aix box.
Try using nawk or gawk instead if awk.


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gawk --- produce the output in pattern space instead of END space

hi, I'm trying to calculate IP addresses and their respective calls to our apache Server. The standard format of the input is HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST IP DATE/TIME - - "GET/POST reuest" "User Agent" HOST... (2 Replies)
Discussion started by: busyboy
2 Replies

2. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

3. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

4. Fedora

Need to incrwase PHYSICAL VOLUME space on hard drive with free space on it

Hi, I run Fedora 17. I created a physical volume of 30GB on a disk with 60GB of space so there is 30GB of free space. On the physical volume, I created my volume group and logical volumes. I assigned all the space in the physical volume to my volume group. I need to add the 30GB of free space... (1 Reply)
Discussion started by: mojoman
1 Replies

5. Solaris

No space left on device but free space and inodes are available...

hi guys, me again ;) i recently opened a thread about physical to zone migration. My zone is mounted over a "bigger" LUN (500GB) and step is now to move the old files, from the physical server, to my zone. We are talking about 22mio of files. i used rsync to do that and every time at... (8 Replies)
Discussion started by: beta17
8 Replies

6. Linux

How to reclaim the space which i used to increse the swap space on Xen,

Hi, i have done a blunder here, i increased the swap space on Xen5.6 server machine using below steps :- 1056 dd if=/dev/zero of=/root/myswapfile bs=1M count=1024 1057 ls -l /root/myswapfile 1058 chmod 600 /root/myswapfile 1059 mkswap /root/myswapfile 1060 swapon /root/myswapfile ... (1 Reply)
Discussion started by: apm
1 Replies

7. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

8. UNIX for Advanced & Expert Users

wake up user space thread from kernel space ISR

Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt. Except for sending a real-time signal, is it possible to use a semaphore? I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies

9. UNIX for Dummies Questions & Answers

How to find a file whick is consuming larger disk space in file system

Hello, Can anybody please tell me the command to find out the filesystem or a file which is consuming larger disk space sing i want to find out the file and want to compress it please help me out any help would be appreciated (6 Replies)
Discussion started by: lokeshpashine
6 Replies

10. Shell Programming and Scripting

How to Delete space from the file

Hi, I want to delete the space from the file. For eg : deep | raj | sis i want the output as deep|raj|sis Please Help me Thanks, Deep (2 Replies)
Discussion started by: deepakpv
2 Replies
Login or Register to Ask a Question