Sponsored Content
Full Discussion: Sorting indented text files
Top Forums Shell Programming and Scripting Sorting indented text files Post 302921475 by kobel on Friday 17th of October 2014 09:33:04 AM
Old 10-17-2014
Hi,

thanks a lot for great suggestion!

Following minor modifications to take into account real Cisco configs (e.g. multi-word section names and different white spaces), the final script looks like this:
Code:
awk '/!/{next} !/^[^A-Za-z0-9 ]+/ {S=$0; print; next} {$0=S " " $0} 1' file | sort | awk '
BEGIN { prefix="test" } 
{  
if ( match($0, prefix) && length($0)>0 ) 
{ sub(prefix, "", $0) } 
else if ( length($0)>0 ) 
{ prefix=$0  } 
print $0  
}'

I post it for other people, who might find it useful.

thanks again!
Miron

Last edited by Franklin52; 10-17-2014 at 03:21 PM.. Reason: Please use code tags, thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting rules on a text section

Hi all My text file looks like this: start doc ... (certain number of records) REC3|Emma|info| REC3|Lukas|info| REC3|Arthur|info| ... (certain number of records) end doc start doc ... (certain number of records)... (4 Replies)
Discussion started by: Indalecio
4 Replies

2. Shell Programming and Scripting

awk error in sorting text file

Hi Having a file as below file.txt error Server Network Name Dept Date Time =========================================================================================================================== 0 ServerA LAN1 AAA IT01 04/30/2008 09:16:26 0 ... (3 Replies)
Discussion started by: karthikn7974
3 Replies

3. UNIX for Dummies Questions & Answers

sorting files with find command before sending to text file

i need help with my script.... i am suppose to grab files within a certain date range now i have done that already using the touch and find command (found them in other threads) touch -d "$date_start" ./tmp1 touch -d "$date_end" ./tmp2 find "$data_location" -maxdepth 1 -newer ./tmp1 !... (6 Replies)
Discussion started by: deking
6 Replies

4. Shell Programming and Scripting

Sorting a text file

In unix how to sort in reverse order based on second field in a text file. $ cat data1 David:501 Albie:503 Shaun:502 The expected output: Albie:503 Shaun:502 David:501 Please help :) (4 Replies)
Discussion started by: jon2ryhme
4 Replies

5. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

6. Shell Programming and Scripting

i need help in sorting two files

i have file a 123 234 456 567 678 and file b 123|xxx|hhh|ppp or zzz 234|rrr|ttt|xxx 432|ttt|mmm|nnn 678|cft|byt|mop i want to compare file a to file b such that when each of the lines in file a can be found in file b column1 and also xxx or hhh or ppp or zzz can be... (12 Replies)
Discussion started by: blackzinga80
12 Replies

7. Shell Programming and Scripting

sorting based on a specified column in a text file

I have a tab delimited file with 5 columns 79 A B 20.2340 6.1488 8.5086 1.3838 87 A B 0.1310 0.0382 0.0054 0.1413 88 A B 46.1651 99.0000 21.8107 0.2203 89 A B 0.1400 0.1132 0.0151 0.1334 114 A B 0.1088 0.0522 0.0057 0.1083 115 A B... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

8. UNIX Desktop Questions & Answers

Problem in sorting a text file

Hi; I have a text file like this: 1 10 11 2 3 4 M X Y When I sort it numerically using sort -n, it looks like this: Y X M 1 2 3 4 10 (3 Replies)
Discussion started by: a_bahreini
3 Replies

9. Shell Programming and Scripting

Complex data sorting in excel files or text files

Dear all, I have a complex data file shown below,,,,, A_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 C_ABCD_13208 0 0 4.16735 141044 902449 1293900 168919 A_ABCDEF715 52410.9 18598.2 10611 10754.7 122535 252426 36631.4 C_DBCDI_1353 0... (19 Replies)
Discussion started by: AAWT
19 Replies

10. Shell Programming and Scripting

Sorting a text file with respect to Function/Keyword

Hello Experts, I am truly a beginner in shell and perl . Need an urgent help with sorting a file. please help. wouldn't mind whether in perl or shell script. Here are the details. ------------------------------------------------------ Input Text file EX:... (9 Replies)
Discussion started by: pradyumnajpn10
9 Replies
Forest::Tree::Builder::SimpleTextFile(3pm)		User Contributed Perl Documentation		Forest::Tree::Builder::SimpleTextFile(3pm)

NAME
Forest::Tree::Builder::SimpleTextFile - Parse trees from indented ASCII files SYNOPSIS
use Path::Class; my $file = file($path); my $builder = Forest::Tree::Builder::SimpleTextFile->new( fh => $file->openr, ); my $tree = $builder->tree; DESCRIPTION
This module replaces Forest::Tree::Reader::SimpleTextFile with a declarative api instead of an imperative one. ATTRIBUTES
fh The filehandle to read from. Required. parser A coderef that parses a single line from "fh" and returns the node depth and its value. Defaults to space indented text. See also "tab_width". tab_width The indentation level for the default parser. Defaults to 4, which means that four spaces equate to one level of nesting. BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. AUTHOR
Yuval Kogman COPYRIGHT AND LICENSE
Copyright 2008-2010 Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-09-27 Forest::Tree::Builder::SimpleTextFile(3pm)
All times are GMT -4. The time now is 09:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy