Sponsored Content
Full Discussion: Parse Directory path - awk
Top Forums Shell Programming and Scripting Parse Directory path - awk Post 303039526 by greycells on Wednesday 9th of October 2019 12:49:18 AM
Old 10-09-2019
Parse Directory path - awk

Hi All,

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

Input file
Code:
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
level1,/level2/level3/level4/ora002/bbu1,20,IBB24
level1,/level2/level3/level4/ora002/ccu1,20,IBB24
level1,/level2/level3/level4/ora003,4,IBB25
level1,/level2/level3/level4/ora003/ddu1,,
level1,/level2/level3/level4/ora004/ttu1,4,IBB25
level1,/level2/level3/level4/ora004/rru1,5,IBB25
level1,/level2/level3/level4/ora005/yyu1,5,IBB25



Output

File1
Code:
level1,/level2/level3/level4/ora001,10,IBB23 
level1,/level2/level3/level4/ora002/bbu1,20,IBB24
level1,/level2/level3/level4/ora002/ccu1,20,IBB24
level1,/level2/level3/level4/ora004/ttu1,4,IBB25
level1,/level2/level3/level4/ora004/rru1,5,IBB25
level1,/level2/level3/level4/ora005/yyu1,5,IBB25



File2

Code:
level1,/level2/level3/level4/ora003,4,IBB25
level1,/level2/level3/leve4/ora003/ddu1,,



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

Code:
level1,/level1/level2/level3/ora001,10,IBB23 
level1,/level1/level2/level3/ora001/blu1,,IBB23 
level1,/level1/level2/level3/ora001/clu1,,IBB23



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; 10-09-2019 at 10:36 AM.. Reason: code tags, please!
 

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

8. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

9. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies
log(n)								 Logging facility							    log(n)

NAME
log - Procedures to log messages of libraries and applications. SYNOPSIS
package require Tcl 8 package require log ?1.0.1? ::log::levels ::log::lv2longform level ::log::lv2color level ::log::lv2priority level ::log::lv2cmd level ::log::lv2channel level ::log::lvCompare level1 level2 ::log::lvSuppress level {suppress 1} ::log::lvSuppressLE level {suppress 1} ::log::lvIsSuppressed level ::log::lvCmd level cmd ::log::lvCmdForall cmd ::log::lvChannel level chan ::log::lvChannelForall chan ::log::lvColor level color ::log::lvColorForall color ::log::log level text ::log::logMsg text ::log::logError text ::log::Puts level text DESCRIPTION
The log package provides commands that allow libraries and applications to selectively log information about their internal operation and state. To use the package just execute package require log log::log notice "Some message" As can be seen above, each message given to the log facility is associated with a level determining the importance of the message. The user can then select which levels to log, what commands to use for the logging of each level and the channel to write the message to. In the following example the logging of all message with level debug is deactivated. package require log log::lvSupress debug log::log debug "Unseen message" ; # No output By default all messages associated with an error-level (emergency, alert, critical, and error) are written to stderr. Messages with any other level are written to stdout. In the following example the log module is reconfigured to write debug messages to stderr too. package require log log::lvChannel debug stderr log::log debug "Written to stderr" Each message level is also associated with a command to use when logging a message with that level. The behaviour above for example relies on the fact that all message levels use by default the standard command ::log::Puts to log any message. In the following example all mes- sages of level notice are given to the non-standard command toText for logging. This disables the channel setting for such messages, assum- ing that toText does not use it by itself. package require log log::lvCmd notice toText log::log notice "Handled by Another database maintained by this facility is a map from message levels to colors. The information in this database has no influence on the behaviour of the module. It is merely provided as a convenience and in anticipation of the usage of this facility in tk-based applica- tion which may want to colorize message logs. API
The following commands are available: ::log::levels Returns the names of all known levels, in alphabetical order. ::log::lv2longform level Converts any unique abbreviation of a level name to the full level name. ::log::lv2color level Converts any level name including unique abbreviations to the corresponding color. ::log::lv2priority level Converts any level name including unique abbreviations to the corresponding priority. ::log::lv2cmd level Converts any level name including unique abbreviations to the command prefix used to write messages with that level. ::log::lv2channel level Converts any level name including unique abbreviations to the channel used by ::log::Puts to write messages with that level. ::log::lvCompare level1 level2 Compares two levels (including unique abbreviations) with respect to their priority. This command can be used by the -command option of lsort. The result is one of -1, 0 or 1 or an error. A result of -1 signals that level1 is of less priority than level2. 0 signals that both levels have the same priority. 1 signals that level1 has higher priority than level2. ::log::lvSuppress level {suppress 1}] (Un)suppresses the output of messages having the specified level. Unique abbreviations for the level are allowed here too. ::log::lvSuppressLE level {suppress 1}] (Un)suppresses the output of messages having the specified level or one of lesser priority. Unique abbreviations for the level are allowed here too. ::log::lvIsSuppressed level Asks the package whether the specified level is currently suppressed. Unique abbreviations of level names are allowed. ::log::lvCmd level cmd Defines for the specified level with which command to write the messages having this level. Unique abbreviations of level names are allowed. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the mes- sage and the message itself, in this order. ::log::lvCmdForall cmd Defines for all known levels with which command to write the messages having this level. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvChannel level chan Defines for the specified level into which channel ::log::Puts (the standard command) shall write the messages having this level. Unique abbreviations of level names are allowed. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvChannelForall chan Defines for all known levels with which which channel ::log::Puts (the standard command) shall write the messages having this level. The command is actually a command prefix and this facility will append 2 arguments before calling it, the level of the message and the message itself, in this order. ::log::lvColor level color Defines for the specified level the color to return for it in a call to ::log::lv2color. Unique abbreviations of level names are allowed. ::log::lvColorForall color Defines for all known levels the color to return for it in a call to ::log::lv2color. Unique abbreviations of level names are allowed. ::log::log level text Log a message according to the specifications for commands, channels and suppression. In other words: The command will do nothing if the specified level is suppressed. If it is not suppressed the actual logging is delegated to the specified command. If there is no command specified for the level the message won't be logged. The standard command ::log::Puts will write the message to the channel specified for the given level. If no channel is specified for the level the message won't be logged. Unique abbreviations of level names are allowed. Errors in the actual logging command are not caught, but propagated to the caller, as they may indicate miscon- figurations of the log facility or errors in the callers code itself. ::log::logMsg text Convenience wrapper around ::log::log. Equivalent to ::log::log info text. ::log::logError text Convenience wrapper around ::log::log. Equivalent to ::log::log error text. ::log::Puts level text The standard log command, it writes messages and their levels to user-specified channels. Assumes that the suppression checks were done by the caller. Expects full level names, abbreviations are not allowed. LEVELS
The package currently defines the following log levels, the level of highest importance listed first. o emergency o alert o critical o error o warning o notice o info o debug KEYWORDS
log, log level, message level, message log 1.0.1 log(n)
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy