12-13-2008
problem with output of find command being input to basename command...
Hi,
I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script.
I am planning to do like this:
if [ `find /path/abc* | wc -l` == 1 ]; then
x=`find /path/abc*`
y=`basename $x`
fi
I am triying to combine x=`find... and y=`basename... into one sentence using "|".
y=`find /path/abc* | basename`
But I am getting below error:
Usage: basename String [Suffix]
Can any one suggest if there is a better way to do this or help me combine these two commands into one.
Thank you.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I am using the following command to extract any log files that are older than 3 days using the following command.
find DIR/LOGDIR -type f -mtime +3 |grep LOG > log_list.out
The results are
DIR/LOGDIR/1.LOG
DIR/LOGDIR/2.LOG
DIR/LOGDIR/3.LOG
DIR/LOGDIR/4.LOG
How do inculde (basename... (4 Replies)
Discussion started by: sam_78_nyc
4 Replies
2. Shell Programming and Scripting
This site has been very helpful thus far.. I thank you all in advance for sharing the knowledge. Let me get to it.
I am trying to write a very small script to take away from the boredom of doing the same thing over and over.
Everynow and again I have to get the hex value of a file using a... (2 Replies)
Discussion started by: BkontheShell718
2 Replies
3. Shell Programming and Scripting
Hi guys. Is it possible (I'm sure it is) to use the output of a simple 'ls' command as input of another command 'tail'.
It is not really the output of the 'ls'. I have to useeach line of the output.
This is the first command...
ls *myFile*021308*
Which it outputs many filenames. For each... (3 Replies)
Discussion started by: rodrimuino
3 Replies
4. Shell Programming and Scripting
Hi guys...
I am new to this scripting...so please forgive me if anything worng in my questions...
here is my question..
I have file structure
/home/oracle/<sid>/logs/bkup
now i want to write a script which should grep the sid name from a file..and it should replace the <SID> with... (1 Reply)
Discussion started by: troubleurheart
1 Replies
5. UNIX for Dummies Questions & Answers
I would appreciate any help.
I need to run 'ps -ef | grep 'process', get the process id and kill that process.
I have got this far:
- Get pid using ps -ef | awk '/process/{ print $2}'
after this I'm kind of stuck..
- Use pipe to redirect the output to kill
pid=ps -ef | awk '/bmserver/{... (2 Replies)
Discussion started by: foxtron
2 Replies
6. Shell Programming and Scripting
Hi All,
How do I provide the output of a command to another command which is waiting for an input from the user ?
Ex : I need to login to a device via telnet. In the script, initially I use the "read" command to get the IP Address, Username and Password of the device from the user. Now,... (1 Reply)
Discussion started by: sushant172
1 Replies
7. UNIX for Dummies Questions & Answers
Hi,
I would like to know if this is possible, and if so what can i do to make this work.
I would like to grep a line X from fileA and then use the output to replace a word Y in fileB.
grep "line X" fileA | sed -e 's/Y/X/g' > outfile
this statement does not work, as i do not know how to... (7 Replies)
Discussion started by: cavanac2
7 Replies
8. Shell Programming and Scripting
I have a file
fileinput.txt:
File home/me/fileA.doc is size 232
File home/you/you/fileB.doc is size 343
File /directory/fileC.doc is size 433
File /directory/filed.doc cannot find file size
I want to use the basename command (or any other command) to output:
File fileA.doc is... (3 Replies)
Discussion started by: linuxkid
3 Replies
9. Shell Programming and Scripting
Hi All,
Hoping you can help as im in desperate need... I'm very new to unix scripting so apoligies,
I have setup an expect script in order to log into a node on our network, This will provide an output as per the below
*********** information:
*************: n/a
TEST IP : n/a
... (18 Replies)
Discussion started by: mutley2202
18 Replies
10. UNIX for Dummies Questions & Answers
Hello nix Experts,
I am a *nix rookie and have run into this issue, can some one help me here and let me know what I am doing wrong.
/home/user1> while read n
> do
> echo $n
> done < <(find . -type f -ctime -1 | grep abc)
I am getting the below error:
-sh: syntax error near... (5 Replies)
Discussion started by: babyPen1985
5 Replies
LEARN ABOUT HPUX
basename
basename(3C) basename(3C)
NAME
basename(), dirname() - extract components of a path name
SYNOPSIS
DESCRIPTION
takes the path name pointed to by path and returns a pointer to the final component of the path name, deleting any trailing '/' characters.
If the string consists entirely of '/' characters, returns a pointer to the string "/". If path is a null pointer or points to the empty
string, returns a pointer to the string ".".
takes the path name pointed to by path and returns a pointer to a string that is a path name of the parent directory of that file. If path
is a null pointer, points to the empty string, or does not contain a '/' character, then returns a pointer to the string ".".
RETURN VALUE
returns a pointer to the final component of path.
returns a pointer to a string that is the parent directory of path.
EXAMPLES
The following code fragment calls and
WARNINGS
and may overwrite path.
and in non-threaded applications currently use a static buffer in each function to hold the result string. Any subsequent calls to and may
overwrite the static buffer. At some release after HP-UX 11i Version 1, HP may use to allocate the buffers. Once allocated, those buffers
will be reused and their addresses will not change; however, if the fails, and would return "." and would be set to
AUTHOR
and were developed by HP.
SEE ALSO
basename(1), thread_safety(5).
STANDARDS CONFORMANCE
basename(3C)