Parsing a PATH statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing a PATH statement
# 1  
Old 03-11-2015
Parsing a PATH statement

I have a script that will be placing a trigger file for other applications.

The user-inputted path is similar to:
Code:
"/data/region/NorthAm/Project HAV 8H"

The project path will not change throughout the script. However, pwd changes as the scanning continues in the script. I need to truncate everything after the project directory "/data/region/NorthAm/Project HAV 8H" so I can apply specific subdirectories for additional trigger files. There are hundreds of subdirectories under each main project path that is inputted by the user, so I need this to be an efficient script, but I can't seem to figure out how to get this done.
Code:
#!/bin/bash
# client inputted directory 'xdir'
xdir=$1
echo $1
 
# other application directories
InclDir="Test, Dev, Prod"
 
# Main Statement
for i in $InclDir
do
echo $i
ndir=$(awk -F/ '{print "/"$2"/",$3"/",$4,"/"$5,"/"%6}`<<< "${xdir}")
echo ${ndir}/${i}
# touch ${ndir}/${i}/${tmp}${dte}.tmp
done

The awk command places spaces in the path, so I know that what I now have doesn't work.

Here is the output of a test run (the touch command commented out for now for obvious reasons)

Code:
Test,
/data/ region/ NorthAm /Project HAV 8H 0/Test,
Dev,
/data/ region/ NorthAm /Project HAV 8H 0/Dev,
Prod
/data/ region/ NorthAm /Project HAV 8H 0/Prod

Is "awk" the only way to get this done? Is there a more efficient way to script this?

Your help in this is greatly appreciated!

Last edited by rbatte1; 03-11-2015 at 03:03 PM..
# 2  
Old 03-11-2015
Look at the basename utility.
# 3  
Old 03-11-2015
Keep the variable with the base directory (xdir), and simply append the work directories.
Code:
for i in Test Dev Prod
do
 ndir="$xdir/$i"
 echo "$ndir"
done

# 4  
Old 03-11-2015
That's It! Thanks for helping the newbie!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. Shell Programming and Scripting

Variable of Path directory is not parsing in awk

Hi All, i had to split one files into 10 equally. For that i have coded below awk. OUTPUT_FILE=/home/sit/path/Files/file_EXPORT.lst DIR_NM=`dirname ${OUTPUT_FILE}` awk -v CURR_DATE="$(date +'%d-%m-%Y-%H-%M')" -v pth=$DIR_NM '{print >> pth/"tgt_file_name"CURR_DATE"_"NR%10 }' ${OUTPUT_FILE} ... (7 Replies)
Discussion started by: looney
7 Replies

3. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

4. Shell Programming and Scripting

Bash script not parsing file with spaces in path

Hi everyone, I'm trying to write my first ever shell script, the OS is Raspbian. The code I have written must be executed whenever a certain database has been modified. The database resides on a Windows server to which I have a mount point, and I have no control over the Windows server at all so... (2 Replies)
Discussion started by: gjws
2 Replies

5. Shell Programming and Scripting

parsing path

Can somebody show me a sed or awk command that can parse a pathname My input will look like this /u01/app/oracle/diag/rdbms/ifddb1/ifddb1 I would like my output to get rid of everything including the "/" before diag. So my output will be this diag/rdbms/ifddb1/ifddb1 I need... (1 Reply)
Discussion started by: BeefStu
1 Replies

6. Shell Programming and Scripting

Help with directory path parsing

I've been working on a UNIX script (csh) that will be starting a java application The goal is to get the version number and location (needed by the application) from the path of the script Example: Location of the script= /apps/myapp/versionNum/script/start.csh I need:... (8 Replies)
Discussion started by: brianjbrady
8 Replies

7. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

8. Shell Programming and Scripting

How to get path and check in if statement

Hi, I was wondering if it possible to get the path of a variable and compare that to something. Basically I want to write a script that checks if my $JAVA_HOME is correct and if not then it sets it. So far I have... if ] then export JAVA_HOME='/pathhere' echo JAVA_HOME='/pathhere' fi ... (6 Replies)
Discussion started by: eltinator
6 Replies

9. Shell Programming and Scripting

(sed) parsing insert statement column that crosses multiple lines

I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)? here is an example: insert into mytable(id, field1, field2)... (3 Replies)
Discussion started by: jjordan
3 Replies

10. Shell Programming and Scripting

parsing error in if statement

hello, I am trying to parse an error returned by a command inside the if statement but it is just displays the full error instead and then stops. if ; then echo "no such package" else echo "similar version found will use pkgrm" fi the above code just displays please let me know... (2 Replies)
Discussion started by: rakeshou
2 Replies
Login or Register to Ask a Question