awk to parse a directory name?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers awk to parse a directory name?
# 1  
Old 06-02-2009
awk to parse a directory name?

Hi,

I have a directory file name:

/auto/space/user/jen/CED/CED_01MZ/visit1/DCE_2eco/016/echo1

I would like to just get the following outputs into variables such that:

variable1 = /auto/space/user/jen/CED/CED_01MZ/visit1/

and

variable2 = DCE_2eco/016/echo1

I've tried it with awk, but the solution is messy and requires some hard-coding. Any suggestions on how to make this independent of anything inside the directory filename? The only constant will be "/auto/space/user/jen/CED/CED_01MZ/". BTW, this is tcsh, not bash.

Thanks in advance!
# 2  
Old 06-02-2009
Code:
echo '/auto/space/user/jen/CED/CED_01MZ/visit1/DCE_2eco/016/echo1' | nawk -v d='/auto/space/user/jen/CED/CED_01MZ/' '$0 ~ "^" d {match($0,d "[^/][^/]*"); print "var1 = " substr($0, RSTART, RLENGTH-1) ORS "var2 = " substr($0, RLENGTH+2)}'

# 3  
Old 06-02-2009
constant part can be removed

Code:
echo "/auto/space/user/jen/CED/CED_01MZ/visit1/DCE_2eco/016/echo1" | sed 's#/auto/space/user/jen/CED/CED_01MZ/visit1/##g'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse Directory path - awk

Hi All, Need some help in parsing a directory listing .. output into 2 files Input file level1,/level2/level3/level4/ora001,10,IBB23 level1,/level2/level3/level4/ora001/blu1,,IBB23 level1,/level2/level3/level4/ora001/clu1,,IBB23 level1,/level2/level3/level4/ora002,,IBB24... (10 Replies)
Discussion started by: greycells
10 Replies

2. Shell Programming and Scripting

Parse multiple html files in directory

I have downloaded source code for 97 files using: wget -x -i link.txt then run a rename loop: for file in * do mv $file $file.txt done to keep the html tags but make the file a text that can be parsed. In each of the 97 txt files the gene # is variable, but the gene is associated... (15 Replies)
Discussion started by: cmccabe
15 Replies

3. Shell Programming and Scripting

awk to parse df output

Output of the below code includes unmatched date.Please correct it df -k|awk '$4>50 {print $1, "\t"$4,"\t" $7}' It gives output less than 50% also. (5 Replies)
Discussion started by: vinil
5 Replies

4. Shell Programming and Scripting

Parse files in directory and compare with another file

I have two files File 1 in reading directory is of following format Read 1 A T Read 3 T C Read 5 G T Read 7 A G Read 10 A G Read 12 C G File 2 in directory contains Read 5 A G Read 6 T C Read 7 G A Read 8 G A Read 20 A T File2 contains (1 Reply)
Discussion started by: empyrean
1 Replies

5. Shell Programming and Scripting

Parse a file with awk?

Hi guys (and gals). I need some help. I'm running an IVR purely on Asterisk where I capture the DTMFs. After pulsing each DTMF I have Asterisk write to a file with whatever was dialed (mostly used for record-keeping) and at the end of the survey I write all variables in a single line to a... (2 Replies)
Discussion started by: tulf210
2 Replies

6. Shell Programming and Scripting

How to parse filename and one level up directory name?

Hello Experts, I need little help with parsing. I want to parse filename and one level up directory name. sample $1 will consists of /home/username/ABC1/rstfiles4.log /home/username/ABC4/rstfiles2.log /home/username/EDC7/rstfiles23.log /home/username/EDC6/rstfiles55.log... (8 Replies)
Discussion started by: Shirisha
8 Replies

7. Shell Programming and Scripting

Script to parse filenames in a directory and do some actions

Hi All, I don't have much experience in scripting, and couldn't find anything that will help me to write a script I need, hopefully you can help me with it. I have lots of files in one directory with the following file name pattern: 100001-something.ext1 100101-something2.ext2... (4 Replies)
Discussion started by: troman
4 Replies

8. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

9. Shell Programming and Scripting

to parse a directory and its subdirectories and find owner name of files

hi all, i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner. for one file it is " stat -c %U filename " but i need to search for each and every file and record it. thanks in advance (14 Replies)
Discussion started by: vyasa
14 Replies

10. Shell Programming and Scripting

AWK unable to parse

awk -v new=" " ' substr($0, 17, 3) == "ABC" && substr($0, 52, 8) == "00000000" { tr=substr($0, 20, 10); ap=substr($0, 30, 2); ver=substr($0, 32, 2); irver=substr($0, 34, 2); ... (12 Replies)
Discussion started by: COD
12 Replies
Login or Register to Ask a Question