Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data restructuring

Status
Not open for further replies.

carignan

Technical User
Aug 4, 2003
2
US
what is the best way to parse this file??:
/net/volume/test-101/test.txt
/net/volume/test-101/test2.txt
/net/volume/test-101/test3.txt
/net/volume2/test-120/test4.txt
/net/volume2/test-120/test5.txt

into this file:
located in: /net/volume/test-101/
test.txt
test2.txt
test3.txt

located in: /net/volume2/test-120/
test4.txt
test5.txt
----------

the first is an output from a tool i wrote that does a recursive list, greps out the path info, and prints it to a file. thanks so much in advance for the help :).

-c
 
something like this:

nawk -f carignan.awk textFile.txt

#---------------- carignan.awk
BEGIN {
FS=OFS="/"
}

{
file=$NF
$NF=""
dir=$0
arr[dir]= (dir in arr) ? arr[dir] SUBSEP file : file;

}

END {
for (i in arr) {
print "located in: " i;
n=split(arr, filesA, SUBSEP);
for (j=1; j <=n; j++)
print filesA[j]
}
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
#!/bin/sh

PREV=''
while read FILE
do
DIR=`dirname $FILE`
if [ $DIR != &quot;$PREV&quot; ]
then
print \\nlocated in: $DIR
fi
basename $FILE
PREV=$DIR
done < file1
 
thanks so much for the fast reply! i am implementing this now.

-c
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top