## Parse Directory path - awk

 Login or Register for Dates, Times and to Reply

# 1
Parse Directory path - awk

Hi All,

Need some help in parsing a directory listing .. output into 2 files

Input file

Output

File1

File2

Logic 1
rows where $2 has the same path upto 4 dir levels and$4 is same is one sub group . , for example

When the above is true , copy the line(s) where $3 field is not empty to file 1 , rest of the sub group can be discarded and if$3 is empty for all the lines in sub group . , copy all the lines in subgroup to file2

Logic2

for rows where $2 has the same path upto 4 dir levels , but$4 is not same or empty ,copy the line(s) to file 2
Any line(s) with unique $2 for 4 dir levels , but with$3 and $4 not empty will go to file 1 as well Rest of the lines which do not match to above 2 criteria will go to file2 as well Thanks Last edited by vgersh99; 4 Weeks Ago at 11:36 AM.. Reason: code tags, please!  greycells View Public Profile for greycells Find all posts by greycells # 2 Any attempt / idea / thought from your side? I can't see your logics example comply to your specification - none of those$2 values represent the "same path upto 5 dir levels". The first entry has four levels only, the next two have five but are different. Please revise your spec / example.
 RudiC View Public Profile for RudiC Find all posts by RudiC
# 3
Thx ...

my bad ... i edited the question ..
 greycells View Public Profile for greycells Find all posts by greycells
# 4
What about your own approach to solve the problem?
 RudiC View Public Profile for RudiC Find all posts by RudiC
# 5
Hi ,

I have only tried basic shell looping .. if then else stuff ... was looking for something more efficient as there are more than 20,000 lines

Thanks
 greycells View Public Profile for greycells Find all posts by greycells
# 6
Why does

show up in file2?
 RudiC View Public Profile for RudiC Find all posts by RudiC
# 7
Hi ..

## Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. \$home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?...

## 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...

## Parse value from multiple row to create the path

Hi all, Hope all the expert can help me in this situation. Let say I have one file with multiple record like below: NAME=FRAGMENT LANGUAGE=1 DIALECT=0 GENDER=NONE FILE=TEST1 DIRECTORY=D:/DETAILS/1/0/test1.txt END NAME=FRAGMENT LANGUAGE=1 DIALECT=0 GENDER=NONE