Help!! how to get the filename as be shown?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help!! how to get the filename as be shown?
# 1  
Old 07-13-2006
Help!! how to get the filename as be shown?

I am trying to obtain the file name (not including sub file name), however, I still cannot have the string output. Smilie


2 existed files at /tmp, AAA.new and BBB.last
Originally, the output result is needed to be shown as follows,
ex:
SYSTEM NEW LAST
===================
01 AAA BBB



My script was as follows, please kindly review and modify!!

if [ ! ls -t -a $filename/*.new || -a $filename/*.last ]; then
echo "------------NA-------------"

elif [-a $filename\*.new]; then
echo "$SYSTEM\ $filename" | read filename

elif [-a $filename\*.last]; then
echo "$SYSTEM\ $filename" | read filename

fi
# 2  
Old 07-13-2006
There are several errors and one or two other changes. Try:
Code:
if [[ !  -a $filename/*.new || ! -a $filename/*.last ]]; then
    echo "------------NA-------------"
else
   if [[-a $filename/*.new]]; then
      filename="$SYSTEM/$filename" 
   else
      filename="$SYSTEM/$filename" 
   fi
fi

# 3  
Old 07-14-2006
If I get it correctly, you just want the filenames without the extensions.

for i in *; do
ext=`echo $i | awk -F"." '{print "."$2}'`;
filename=`basename $i $ext`;
echo $filename;
done
# 4  
Old 07-17-2006
Network Need your help!!~~

Thanks for your kindly support, but I still cannot run smoothly,
I consider the loop has a issue, the result was as attached,
SYSTEM NEW LAST
==================
pp01 ==========>NA
pp02 ==========>NA
pp03 ==========>NA
pp04 ==========>NA
.........

My script was as follows,

echo "SYSTEM NEW LAST"
echo "======================"
for test_name in $(grep -e "pp" $test_list | awk '{ print $2 }')
do
echo "$test_name\c"
[ $( ls -1 $pc_dir | grep -c $test_name ) -eq 0 ] && echo "$test_name ===========> N/A"
continue

for filename in $( ls -1 $pc_dir )
do
ext=$(echo $filename | awk -F. '{print $2}')
pc_name=$(echo $filename | awk -F _ '{print $2 "_" $3}')

if [ "$ext" = "new" ]
then
echo "$test_name ${pc_name%.new}"

elif [ "$ext" = "last" ]
then
echo "$test_name ${pc_name%.last}"
fi
done
done
# 5  
Old 07-17-2006
Try this (not tested)
Code:
echo "SYSTEM NEW LAST"
echo "======================"

for test_name in $(awk '/pp/ {print $2}')
do
   if ls -1 | grep -q $test_name
   then
      ls -1 $pc_dir |
      while read filename
      do
         pc_name=$(echo $filename | cut -d_ -f1-2)
         ext=$(echo $filename | awk -F. '{print $2}')
         case "$ext" in
            new)  echo $test_name ${pc_name%.new}"  ;;
            last) echo $test_name ${pc_name%.last}" ;;
         esac
      done
   else
      echo "$test_name ===========> N/A"
   fi
done

Jean-Pierre.
# 6  
Old 07-17-2006
Quote:
Originally Posted by Jones Lin
Thanks for your kindly support, but I still cannot run smoothly,
I consider the loop has a issue, the result was as attached,
SYSTEM NEW LAST
==================
pp01 ==========>NA
pp02 ==========>NA
pp03 ==========>NA
pp04 ==========>NA
.........

My script was as follows,

echo "SYSTEM NEW LAST"
echo "======================"
for test_name in $(grep -e "pp" $test_list | awk '{ print $2 }')
do
echo "$test_name\c"
[ $( ls -1 $pc_dir | grep -c $test_name ) -eq 0 ] && echo "$test_name ===========> N/A"
continue

for filename in $( ls -1 $pc_dir )
do
ext=$(echo $filename | awk -F. '{print $2}')
pc_name=$(echo $filename | awk -F _ '{print $2 "_" $3}')

if [ "$ext" = "new" ]
then
echo "$test_name ${pc_name%.new}"

elif [ "$ext" = "last" ]
then
echo "$test_name ${pc_name%.last}"
fi
done
done
Could you provide some sample file names, if it still doesn't works.
# 7  
Old 07-18-2006
Bug

Dear Sirs (Above!),

Thanks for your kindly help!!
I have fixed it and also appreciated your support.
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Public ip is not shown in ifconfig - Ubuntu 16.04

Hello, I have just installed ubuntu 16.04 into my pc. Locally everything works fine, it takes data from internet, I am also able to connect to apache in the same local network. When I try to reach from mobile network, I can't establish ssh, apache site is not displaying in my browser etc. ... (17 Replies)
Discussion started by: baris35
17 Replies

2. UNIX for Dummies Questions & Answers

[CUPS] printers not shown after a while

I'm currently running a CUPS server and it shows the printers on other computers just fine, but after a while they disappear. I found out, that restarting /etc/init.d/cups-browsed fixes the problem (for about 15min). When the printers disappear, the cups-browsed service is still running, so I... (0 Replies)
Discussion started by: Gajeela
0 Replies

3. UNIX for Advanced & Expert Users

Bash-Completion, one list shown, the other not.

Heyas I'm trying to read out a file which contains a variable and use that list to complete a bash command. Difficult part on this is, that 2 (actualy 3) different lists are to be used, but the 'dynamic' ones from the external file dont work properly. It only seems to work with the list... (2 Replies)
Discussion started by: sea
2 Replies

4. Solaris

Using dd command no MB/s shown

Hi I am using the dd command on solaris 10 and the output doesn't include the MB/s statistic that you get in Linux, is this not available or am I missing a switch of some sort #dd if=/dev/urandom of=/perf_test/file.txt bs=1048576 count=500 0+500 records in 0+500 records out (2 Replies)
Discussion started by: eeisken
2 Replies

5. IP Networking

Connections not shown in netstat output

I have a TCPIP server application (a Vendor package) which by default allows 10 connections. It provides a parameter to allow us to increase the maximum allowable connections in case it is needed. Intermittently this application is failing with maximum number of connections reached even when there... (1 Reply)
Discussion started by: AIX_user
1 Replies

6. UNIX for Advanced & Expert Users

Memory usage shown is high

Hello all, I am facing a memory related issue on my linux that is CentOS 4.0. What I see as an output of top command, free command is that memory usage is almost 90% which is quite high without much load on the system. This is continuously showing 90% or so of memory usage with top or free... (2 Replies)
Discussion started by: radiatejava
2 Replies

7. Solaris

sun cluster3.2, d3 and d8 are shown as failed

Hello, This is a 2 node sun cluster 3.2 on solaris 10(x86) I am using an unique ~512M disk (c0d1) on each node and slice 6 on this disk for globaldevices. While everything looks like fine, the 'Fail' is bothering me. @ tommy_sun1 @tommy_sun -bash-3.00# cldevice refresh... (10 Replies)
Discussion started by: upengan78
10 Replies

8. Solaris

what FS is shown in df -kh

Hi, On solaris 10, t5120, I don't understand what are the last 2 file systems so last 2 file systems what are they, why are they getting shown and also confused why the swap is shown so many times and different size when I set it to 16 G at the time of installing solaris 10. ( rest... (3 Replies)
Discussion started by: upengan78
3 Replies

9. Solaris

preventing the banner from being shown

Is there a way to supress the banner from being shown when you log in? (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

10. UNIX for Dummies Questions & Answers

working directory shown

Hi, How do I get my working directory always shown in the unix editor? i.e if I am now at /Home/abc/xyz/, I want to see this absolute path displayed ( and now only display when I type pwd). thanks for the kind help. Regrads (3 Replies)
Discussion started by: swchee
3 Replies
Login or Register to Ask a Question