Parse Directory path - awk


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 8  
Will the data follow a certain sequence, i.e. parent dirs sorted, parent dir before child dir, non-empty $3 before empty $3, non-empty $4 before empty $4?
# 9  
Hi ...

It most likely won't ..
Example it could be something like this .. input i mean

Code:
level1,/level2/level3/level4/ora001,10,IBB23
level1,/level2/level3/level4/ora002,,IBB24
level1,/level2/level3/level4/ora001/blu1,,IBB23
level1,/level2/level3/level4/ora001/clu1,,IBB23
level1,/level2/level3/level4/ora002/bbu1,20,IBB24
level1,/level2/level3/level4/ora002/ccu1,20,

Moderator's Comments:
Mod Comment Please use code tags

Last edited by vgersh99; 1 Week Ago at 10:45 AM.. Reason: code tags, please!
# 10  
Is it possible to e.g.

Code:
sort -t, -k2,2 -k4r -k3 file

This User Gave Thanks to RudiC For This Post:
# 11  
Original File

Code:
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_03,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_02,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN18300/QLN18300,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63500/QLN63500,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2031/PLNLOD2031,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN16800/QLN16800,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001,10,
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63200/QLN63200,10,
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63100/QLN63100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17800/QLN17800,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg001,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg002,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17700/QLN17700,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRAID_RISK_01,,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2071/PLNLOD2071,10,IEE1
slsins,/data/dbdumps-nr/gshins01/syb001,10,IEE1
slsins,/data/dbdumps-nr/gshins01/ggg001,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63600/QLN63600,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLNLOD2125,,IEE1
slsins,/data/applications-nr/gshins01/pCloud,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03,10,IEE1
slsins,/data/application-nr/slsins/CDDS,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17100/QLN17100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLN45100,10,IEE1
slsins,/data/dbdumps-rp/gshins01/sql001,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03/IB_Odyssey_03,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17900/QLN17900,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN64000/QLN64000,10,IEE1


$ sort -t, -k2,2 -k4r -k3 ei
Code:
slsins,/data/application-nr/slsins/CDDS,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRAID_RISK_01,,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_02,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_03,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03/IB_Odyssey_03,10,IEE1
slsins,/data/applications-nr/gshins01/pCloud,10,IEE1
slsins,/data/dbdumps-nr/gshins01/ggg001,10,IEE1
slsins,/data/dbdumps-nr/gshins01/syb001,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001,10,
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLN45100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLNLOD2125,,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2031/PLNLOD2031,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2071/PLNLOD2071,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN16800/QLN16800,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17100/QLN17100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17700/QLN17700,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17800/QLN17800,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17900/QLN17900,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN18300/QLN18300,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63100/QLN63100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63200/QLN63200,10,
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63500/QLN63500,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63600/QLN63600,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN64000/QLN64000,10,IEE1
slsins,/data/dbdumps-rp/gshins01/sql001,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg001,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg002,10,IEE1

$ more file1
Code:
slsins,/data/application-nr/slsins/CDDS,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_02,10,IEE1
slsins,/data/application-nr/slsins/MYRIAD/MYRIAD_RISK_03,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03,10,IEE1
slsins,/data/application-rp/slsins/Odyssey/Odyssey_26656_03/IB_Odyssey_03,10,IEE1
slsins,/data/applications-nr/gshins01/pCloud,10,IEE1
slsins,/data/dbdumps-nr/gshins01/ggg001,10,IEE1
slsins,/data/dbdumps-nr/gshins01/syb001,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLN45100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2031/PLNLOD2031,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_PLNLOD2071/PLNLOD2071,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN16800/QLN16800,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17100/QLN17100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17700/QLN17700,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17800/QLN17800,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN17900/QLN17900,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN18300/QLN18300,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63100/QLN63100,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63500/QLN63500,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63600/QLN63600,10,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN64000/QLN64000,10,IEE1
slsins,/data/dbdumps-rp/gshins01/sql001,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg001,10,IEE1
slsins,/data/dbdumps-rp/slsins/ggg002,10,IEE1


$ more file2
Code:
slsins,/data/application-nr/slsins/MYRIAD/MYRAID_RISK_01,,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001,10,
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_DLNLOD2125,,IEE1
slsins,/data/dbdumps-nr/slsins/ggg001/DMP_QLN63200/QLN63200,10,

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Medium
The Western Electric Model 500 telephone uses tone dialing to dial phone numbers.
True or False?

9 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

3. Shell Programming and Scripting

Parse output path to set variable

I am looking to parse a text file output and set variables based on what is cropped from the parsing. Below is my script I am looking to add this feature too. All it does is scan a certain area of users directories for anyone using up more than X amount of disk space. It then writes to the... (4 Replies)
Discussion started by: es760
4 Replies

4. Shell Programming and Scripting

Parse file name out of UNC path

Hello, I searched the forums and didn't see a situation like this: I cannot figure out how to parse out just the file name from the full path. The path looks like this: \\foo\bar\filename.ext I don't think something like 'cut' will work so I tried to whip up a regex but couldn't get it... (12 Replies)
Discussion started by: bytesnoop
12 Replies

5. Shell Programming and Scripting

sed/awk for extracting directory from file path

Hi, I have following path: set file_path = D:/forums/prac/somedir/new1/file1.txt or set file_path = E:/new/forums1/prac/somedir/new2/file2.txt I need to grep "somedir" from file path. In this case preceding directory "prac" remains same for both the paths, but directories preceding... (7 Replies)
Discussion started by: sarbjit
7 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

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?... (7 Replies)
Discussion started by: royzlife
7 Replies

8. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: nixjennings
2 Replies

9. Shell Programming and Scripting

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 (13 Replies)
Discussion started by: shirleyeow
13 Replies

Featured Tech Videos