Sponsored Content
Top Forums Shell Programming and Scripting Scan directories and create a list of files Post 302958420 by RavinderSingh13 on Thursday 22nd of October 2015 03:11:45 AM
Old 10-22-2015
Hello jiam912,

Could you please try following and let me know if this helps you.
Code:
awk '/^jd/{A=$0;next} {sub(/^[[:space:]]+/,X,$0);} ($0 ~ /tp/){B=$0} ($0 ~ /txt/){Q[B]=Q[B]?Q[B] ORS A"/"B"/"$0"/sizefile":A"/"B"/"$0"/sizefile"} END{for(j in Q){E=j;sub(/[[:space:]].*/,X,E);print E ORS Q[j]}}' Input_file

Output will be as follows.
Code:
tp1
jd175-1/tp1/1.txt/sizefile
jd175-1/tp1/2.txt/sizefile
jd176-1/tp1/3.txt/sizefile
jd176-1/tp1/4.txt/sizefile
jd177-1/tp1/5.txt/sizefile
jd177-1/tp1/6.txt/sizefile
tp2
jd175-1/tp2/1.txt/sizefile
jd175-1/tp2/2.txt/sizefile
jd176-1/tp2/3.txt/sizefile
jd176-1/tp2/4.txt/sizefile
jd177-1/tp2/5.txt/sizefile
jd177-1/tp2/6.txt/sizefile

EDIT: Adding a non one-liner form of solution on same.
Code:
awk '/^jd/{
                A=$0;
                next
          }
          {
                sub(/^[[:space:]]+/,X,$0);
          }
                ($0 ~ /tp/) {
                                B=$0
                            }
                ($0 ~ /txt/){
                                Q[B]=Q[B]?Q[B] ORS A"/"B"/"$0"/sizefile":A"/"B"/"$0"/sizefile"
                            }
     END{
                for(j in Q) {
                                E=j;
                                sub(/[[:space:]].*/,X,E);
                                print E ORS Q[j]
                            }
          }
    ' Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 10-22-2015 at 04:15 AM.. Reason: Adding a non one-liner form of solution.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scan directory and sub directories

I am really stuck on a issue and have not been able to find a solution. With the code below I need to not only scan the current directory which as you can see below is... /lcl/sit/apps/Tivoli/ But I also want it to scan all sub directories it finds under Tivoli as well for the same thing... (2 Replies)
Discussion started by: LRoberts
2 Replies

2. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

3. Shell Programming and Scripting

Create unique tar archives from a list of directories

I'm looking to archive a client directory from a CIFS share There are multiple directories that will be stored in a text file and I'm looking to create an individual tar archive of each folder in the directory. I've tried a number of commands to no avail. Here's what I would like. ... (2 Replies)
Discussion started by: Steelysteel
2 Replies

4. Shell Programming and Scripting

create more than 100 directories and copy files into them

Hi, I have several files containing experiment measurements per hour (hour_1.txt has measurements for first hour, etc..etc..). I have 720 of these files (i.e. up to hour_720.txt) and i want to create 720 directories and in every one of them i want to copy its associative file (e.g.... (4 Replies)
Discussion started by: amarn
4 Replies

5. UNIX for Dummies Questions & Answers

list directories with more than X files

I want to search a server beginning at /home and list directories with more than X files I found a hack that injects tons of files into a directory How can I search the server recursively and list directories with more than X files? Thank you! like, find /home (directories, that meet the... (5 Replies)
Discussion started by: vanessafan99
5 Replies

6. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

7. Shell Programming and Scripting

Copy of "How to create a long list of directories with mkdir?"

To bakunin and corona688: My result when text in file is ms_ww_546 ms_rrL_99999 ms_nnn_67_756675 is https://www.unix.com/C:\Users\Fejoz\Desktop\ttt.jpg I hope you can see the picture. There is like a "whitespace character" after 2 of the 3 created directories. ---------- Post... (0 Replies)
Discussion started by: setub
0 Replies

8. Shell Programming and Scripting

How to create a long list of directories with mkdir?

Hi... Thanks to read this... I want to use mkdir to create many directories listed in a text file, let's say. How do I do this? Sorry for this maybe very basic question :) (13 Replies)
Discussion started by: setub
13 Replies

9. Shell Programming and Scripting

Alignment tool to join text files in 2 directories to create a parallel corpus

I have two directories called English and Hindi. Each directory contains the same number of files with the only difference being that in the case of the English Directory the tag is .english and in the Hindi one the tag is .Hindi The file may contain either a single text or more than one text... (7 Replies)
Discussion started by: gimley
7 Replies
XDeltadir(1)						      General Commands Manual						      XDeltadir(1)

NAME
xdeltadir - Invoke XDeltadir SYNOPSIS
xdeltadir subcommand [ operand... ] DESCRIPTION
XDeltadir is a perl script that wraps around the XDelta program. XDeltadir provides the ability to generate deltas between files in the two directories and later apply those deltas. It operates similar to the diff and patch commands, but works on binary files stored in two different directories and does not produce a human readable output. XDeltadir has two subcommands, delta and patch. Delta accepts two directories and produces a delta, while patch accepts the original direc- tory and a delta and produces the other directory. As opposed to the the diff(1) format, which can usually be reversed, these deltas are one way. Subcommands Each subcommand will be detailed seperately. In general, any input file may be compressed with gzip(1) and XDelta program called from XDeltadir will automatically uncompress it into a temporary location before examining the file. This temporary location is either the value of the environment variable, if set, or "/tmp". Unless turned off, XDelta always verifies the integrity of reconstructed files with MD5 checksums. By default, XDelta compresses constructed deltas. Delta The delta subcommand has the following synopsis: xdeltadir delta from_dir to_dir patch_dir Computes a deltas for the files from from_dir to to_dir and writes them to patch_dir Patch The patch subcommand has the following synopsis: xdeltadir patch patch_dir from_dir to_dir Applies patches from patch_dir to files from from_dir The from files must be identical to the ones used to create the deltas. Its MD5 checksum is used to verify this condition. The constructed files and directories will be written to to_dir All the directories must exist before running the xdeltadir. SEE ALSO
xdelta (1) IDENTIFICATION
Author: Radim Gelner, <radim.gelner@suse.cz> Manual Page Revision: 1.0; Release Date: Fri Jan 26 11:53:23 CET 2001 Copyright (C) 2001 XDeltadir(1)
All times are GMT -4. The time now is 02:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy