Sponsored Content
Top Forums Shell Programming and Scripting getting the path part of an argument Post 48946 by ropers on Monday 22nd of March 2004 11:38:17 AM
Old 03-22-2004
getting the path part of an argument

Seems I'm inundating this forum with questions, but anyway:

I am writing a script that should accept one and only one argument when called.

That argument should designate a file, either with path/filename or just filename.

Now to the difficult bit:

I want to figure out a way to store just the path in one variable and just the file name in another. I need this for subsequent manipulation.

I thought I should be able to do this with sed or awk, but I couldn't figure it out.
Also, I am fundamentally unsure whether it's a good idea to just look for the last "/" in the argument.

So I'm going to ask the one question I am starting to get famous for: is there a better way to achieve what I want?

The below code is what I currently have, giving you the context this is for, not tremendously important, but just so you can see where I'm going:
Code:
if [ $# -eq 1 ] && [ -r "$1" ] && [ -f "$1" ] && [ `wc -c "$1" | awk '{print $1}'` -gt 681574400 ]; then 
# I should add a check whether the current dir is writable 
	# there is only one parameter AND it\'s writable AND it\'s an ordinary file AND it\'s bigger than 650MB
	split -b650m "$1" "$1"'.carved.'
	#echo "last error:"
	#echo $?
	# check how split reacts when given a file smaller than 650MB
	
	slices=( $(ls . | grep "$1.carved." | grep -v "rejoin.$1") )
		
	# echo "Number of slices:"
	slice_count=${#slices[@]}
	# echo $slice_count
	
	echo "#!/bin/sh" > "rejoin.$1"
	index=1
	while [ "$index" -lt "$slice_count" ]; do
		echo "cat ${slices[$index]} >> ${slices[0]}" >> "rejoin.$1"
		let "index = $index + 1"
	done
	echo "mv ${slices[0]} \"$1\"" >> "rejoin.$1"
	echo "exit" >> "rejoin.$1"
	chmod 755 "rejoin.$1"
	echo "Generated rejoin script."

	exit 0;
else
	echo "carve - carves up a (large) file into 650MB pieces";
	echo
	echo "usage: carve <filename>";
	echo 
	echo "carve also generates a \"rejoin\" script for future reassembly"; 
	# That's because I want the user to have no excuse for not including a 
	# surefire rejoin script when putting these files somewhere.
	# We don't want some other user end up with a bunch of confusing files
	# s/he doesn't know how to deal with.
	# This "included" generation out of this script is also to minimize 
	# dependencies.
	exit 1
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Maximum length of a path given as an argument to a shell script

hi, I am using solaris10. I have to write a bourne shell script, which copies files for the said destination path which is passed as an argument to the script. it looks like this myscript.sh /var/test -->destination path now i would like to know what is the maximum length i can... (3 Replies)
Discussion started by: raghu.amilineni
3 Replies

2. Shell Programming and Scripting

retrieve part of file path

Hi I am trying to use sed to retrieve part of my html file's path. I am having a hard time getting what I want. Could someone give me some help? I want to retrieve the section after html and before the file name For example if I have the following, ... (3 Replies)
Discussion started by: tiger66
3 Replies

3. Shell Programming and Scripting

regex to select last part of a path

Hi all, I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name. Something like: /dir1/dir2/dir2 and I want to select the last /dir2 where dir2 can be any kind of string. Thanks a lot for your help.... (7 Replies)
Discussion started by: elric
7 Replies

4. Shell Programming and Scripting

taking a part of string from a given path

Hi I have two path as follows system/console/bin/code/sample/testfile.txt system/console/bin/database/files/new/dbfile.txt I need the output as code/sample in first case database/files/new in second case That is I am omitting system/console/bin and the filename(s) in both... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

5. UNIX for Advanced & Expert Users

How do i use vi to substitute an expression that is part of a path?

Let say I have /home/user1/bin/ and i want it to be /root/bin I tried : s/\/home\/user1/user2/ but it can't find the pattern user1. I tried: s/*\/home\/user1*/user2/ as well same result many thanks (4 Replies)
Discussion started by: c00lsnoopy
4 Replies

6. UNIX for Advanced & Expert Users

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (0 Replies)
Discussion started by: KidD312
0 Replies

7. Programming

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (1 Reply)
Discussion started by: KidD312
1 Replies

8. Shell Programming and Scripting

Pass argument in script to run specific part in that

Hello Friends, I need you help ! I have a scripts names runsteps.sh which contains command to run bunch of commands for each application you want to install " Oracle " Jboss" etc echo " Which app you want to install Jboss" ? Yes or no? read ans depending on Yes or not it goes inside... (3 Replies)
Discussion started by: saurabh84g
3 Replies

9. Shell Programming and Scripting

Identify full path in argument

I have a small script to send copies of files to another computer used for tests but in the same location:pwd=`pwd` for i in "$@" do echo "rcp -p $i comp-2:$pwd/$i" rcp -p $i comp-2:$pwd/$i echo "Finished with $i" doneIs there a way I can check the parameter to see if it is a full... (5 Replies)
Discussion started by: wbport
5 Replies

10. UNIX for Advanced & Expert Users

A way to print only part of directory path

Hi, So I struggled to find a solution to the following problem: I want to make sed print only part of multiple different paths. So lets say we have /path/path1/path2/logs/bla/blabla /path/path1/path2/path3/logs/yadda/yadda/yadda Can someone suggest a way to make sed or other... (5 Replies)
Discussion started by: dampio
5 Replies
JAVA2HTML(1)						      General Commands Manual						      JAVA2HTML(1)

NAME
java2html - generates highlighted html-files from Java or C++ source SYNOPSIS
java2html [options] [filename...] DESCRIPTION
This manual page documents how to use java2html. If no arguments are given on the command line of java2html, it reads from stdin and writes to stdout. If invoked with filenames as arguments java2html will write it's output into new files. Names of output files are generated by appending ".html" to the corresponding input filename. Installing as a CGI program java2html can be installed as a CGI program and convert source files on the fly. In order to set this up for apache the webmaster has to add the two lines AddType text/x-java .java Action text/x-java /cgi-bin/java2html to the webserver configuration file. java2html depends on the webserver properly setting environment variable PATH_TRANSLATED to the path- name of the source file. If java2html has been compiled with option -DCOMPRESSION=1 then it will invoke gzip to compress the generated HTML before sending it to the requesting browser. Of course java2html takes care to check if the browser accepts gzip encoding. OPTIONS -- Interpret all following arguments on the command line as filenames. This is useful, if you want to convert files beginning with a '-'. -b filename Insert the file 'filename' after converted data and before HTML footer. See also the -s option. -c Turns off CGI-script detection and HTTP header generation. This is needed to use java2html as a subcommand in another CGI script. -h filename Insert the file 'filename' after the HTML headers and before the converted data. See also the -s option. -i Generate an index only. This will generate a list of references (HREF's) to the labels that java2html creates for your source file. The references are created as list items (<li>) in an HTML list. Each line has the form <li><a href="#name">prototype()</a></li> so they can be used directly as an index list, or further parsed by another script. If you want the index at the top of the source file, you will need a wrapper script like this one: #! /bin/sh echo "Content-type: text/html" echo "" echo "<html>" echo "<head><title>$PATH_TRANSLATED</title>" echo "<meta name="generator"" echo "content="`java2html -V`">" echo "</head>" echo "<body>" echo "<h1>Source of $PATH_TRANSLATED</h1>" echo "<ul>Structures and functions" cat $PATH_TRANSLATED | java2html -isc echo "</ul>" echo "<hr></hr>" cat $PATH_TRANSLATED | java2html -sc echo "</body></html>" exit -n Number lines and label them with 'line' followed by the line number. Empty lines get no label, but the linecounter will count them nevertheless. With this feature you can refer to special lines of code from other parts of the generated file or from external files with a line like this: <A HREF="foo.java.html#line301">Go to line 301</A> -s With this option you can suppress the generation of HTML headers. This is especially useful together with options -b file and -h file. -t title Set the title to 'title'. The default is the filename you converted or "stdin" if reading from stdin. This option is only used if -s is not set. -u Print usage information. -w width sets the WIDTH attribute for HTML tag <PRE>. If this option is not used a default of 80 is assumed. (Currently most browsers are ignoring this attribute). -V reports the version number of java2html. EXIT STATUS
java2html returns 0 on success, 1 if input files are not existing/readable, 2 if output files are not creatable/writable, 3 if invoked with illegal options and 4 if gzip cannot be invoked. AUTHORS
Florian Schintke <schintke@cs.tu-berlin.de> Martin Kammerhofer <mkamm@gmx.net> wrote the CGI feature. Rob Ewan <rob@ewan.com> wrote the indexing feature. SEE ALSO
c2html(1), pas2html(1), perl2html(1). JAVA2HTML(1)
All times are GMT -4. The time now is 12:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy