Sponsored Content
Top Forums Shell Programming and Scripting How to select the shortest path in grep search? Post 302653763 by alister on Sunday 10th of June 2012 10:07:03 AM
Old 06-10-2012
Quote:
Originally Posted by Scrutinizer
Actually we should count the sequences of non-slashes to find the least deepest path, so that we do not count leading, ending and double slashes ( leaving paths with ../ out of the equation Smilie )
Code:
awk 'NR==1 || gsub(/[^\/]+/,"&")<m{m=NF; p=$0} END{print p}' infile

That solution doesn't handle consecutive slashes properly. Specifically, m=NF renders the comparison of gsub's return value meaningless.

Feeding the following pathological data should demonstrate the problem:
Code:
A/B/C/configure
A/////B/configure

I'll leave the correction as an exercise for someone else, but I believe that using this approach requires storing the return value of gsub for subsequent comparison.

Regards,
Alister
This User Gave Thanks to alister For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Select records based on search criteria on first column

Hi All, I need to select only those records having a non zero record in the first column of a comma delimited file. Suppose my input file is having data like: "0","01/08/2005 07:11:15",1,1,"Created",,"01/08/2005" "0","01/08/2005 07:12:40",1,1,"Created",,"01/08/2005"... (2 Replies)
Discussion started by: shashi_kiran_v
2 Replies

2. Shell Programming and Scripting

How to select the path that contains a certain string from a certain file?

Hi, I am new to this world of shell programming. I am facing a problem that is : I have directory which has many sub directories at different depth. say A/B/C/files A/B/files A/B/C/D/files In this directory structure there exists a file called ".project" in some of the sub... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

3. Shell Programming and Scripting

regex to select last part of a path

Hi all, I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name. Something like: /dir1/dir2/dir2 and I want to select the last /dir2 where dir2 can be any kind of string. Thanks a lot for your help.... (7 Replies)
Discussion started by: elric
7 Replies

4. Programming

Implementing a shortest path algorithm in C

Hello, I have a question. I have to implement a shortest path algorithm in n*n grid, moving from one coordinate to another coordinate. But i have no clue how to start. Can anyone help? Thanks a tonn in advance! (1 Reply)
Discussion started by: mind@work
1 Replies

5. Shell Programming and Scripting

search & select text

hi people; from my file:... ... ... 101221-18:45:17 192.168.1.1 1.0 PortNodeModel ========================================================= Object Attribute Value ========================================================= SectorPort=3 switchport 20 SectorPort=1 switchport 10 SectorPort=2... (12 Replies)
Discussion started by: gc_sw
12 Replies

6. UNIX for Advanced & Expert Users

SQLPlus Select with Grep

I m trying to grep 'select * from' from a script, but the problem is with the * ... I think its taking * as some special character ... when I try to do grep '*' test (test is my test file) its displaying * But when I am trying to do grep 'select * from' test its not showing anything... (2 Replies)
Discussion started by: RDR
2 Replies

7. Shell Programming and Scripting

How to select First two directory in from path name?

Can somebody help me on below question I have path and i want to select first two directory name in variable how we can do this. /Myname/xyz/yourname/abc/somebodyname i want to select /Myname/xyz in variable. Quick help will be appriciated. Thanks in advance Regards, Kumar (10 Replies)
Discussion started by: yadavricky
10 Replies

8. Shell Programming and Scripting

Select only line numbers using grep

Hai, I want to select only line numbers into a file if some pattern matches. I have written my script like below but its not working. #!/bin/sh file='/home/testfile1' filesearch='/home/test00' while read line do search=`echo $line |cut -c 1-24` echo $search echo `grep -n ""... (3 Replies)
Discussion started by: Subbu123
3 Replies

9. Shell Programming and Scripting

Shortest path for each query from a csv file

Hi all, I have this file __DATA__ child, Parent, probability, M7, Q, P, M7, M28, E, M28, M6, E, M6, Q, Pl, & several hundred lines..... Legends: P(= Probable) > Pl(=Plausible) > E(=Equivocal). What I want is for each child I want to trace it... (5 Replies)
Discussion started by: rushadrena
5 Replies

10. Homework & Coursework Questions

Need help how to search for shortest line from a file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to write a program that have to read every standard input then print out the line number and the content of... (10 Replies)
Discussion started by: scopiop
10 Replies
srf_list(1)							   Staden io_lib						       srf_list(1)

NAME
srf_list - Lists and/or counts the contents of an SRF file SYNOPSIS
srf_list [options] srf_archive ... DESCRIPTION
srf_list lists the filenames held within one or more SRF container. To simply count the contents rather than list them specify the -c option. Note that when in count-only mode if an index is present it will be used to determine the number of entries in the index and hence sequences in the SRF file. The index cannot be used when listing the filenames however as the index itself does not contain the full file- names. Note that it is not possible to count sequences matching certain patterns or with specific flags set. srf_info is a more general purpose tool that may cover this. OPTIONS
-c Counts sequences instead of listing them. Note that this may be substantially faster than listing if an index exists. -v Verbose mode. This gives summary count information per file rather than just the total at the end. -l Long format. When listing sequence names this also provides information on the position in the archive and the size of the sequence specific data block and the size of the shared data block header. EXAMPLES
To count the total number of sequences in several SRF files: srf_list -c *.srf To produce a "fofn" (file of filenames) for an SRF file: srf_list foo.srf > foo.fofn AUTHOR
James Bonfield, Wellcome Trust Sanger Institute September 29 srf_list(1)
All times are GMT -4. The time now is 06:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy