Order text by delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Order text by delimiters
# 1  
Old 10-28-2009
Order text by delimiters

I try order the content from file by delimiters.
This is the text:

Code:
interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

and the result that I need is:
Code:
interface Loopback0,description !!!RID RR_SLT, ip address 172.31.128.19 255.255.255.255 (line 1)

interface GigabitEthernet0, description !!!P_SLT GI0/0/9, ip address 172.31.130.246 255.255.255.252 (line2)

Is this possible?

Thanks.

Last edited by radoulov; 10-28-2009 at 04:41 PM.. Reason: Use code tags, please!
# 2  
Old 10-28-2009
Something like this should do the trick:

Code:
awk '{$1=$1}1' FS="\n" RS= OFS="," file

# 3  
Old 10-31-2009
Code:
local $/="\n\n";
while(<DATA>){
	s/\n/, /g;
	print $_,"\n";
}
__DATA__
interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

# 4  
Old 11-02-2009
Works, thanks!...but how redirect the result to file!. Sorry for my english again.
Quote:
Originally Posted by Franklin52
Something like this should do the trick:

Code:
awk '{$1=$1}1' FS="\n" RS= OFS="," file

# 5  
Old 11-02-2009
Code:
awk '{$1=$1}1' FS="\n" RS= OFS="," file > out

# 6  
Old 11-02-2009
Quote:
Originally Posted by mkastin
Code:
awk '{$1=$1}1' FS="\n" RS= OFS="," file > out

Thanks for all! Smilie
# 7  
Old 11-03-2009
perl:
Code:
local $/="\n\n";
while(<DATA>){
	s/\n/ /g;
	s/$/"(line ". $. .")"/e;
	print $_,"\n";
}
__DATA__
interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

find & Replace text using two non-unique delimiters.

I can find and replace text when the delimiters are unique. What I cannot do is replace text using two NON-unique delimiters: Ex., "This html code <text blah >contains <garbage blah blah >. All tags must go,<text > but some must be replaced with <garbage blah blah > without erasing other... (5 Replies)
Discussion started by: bedtime
5 Replies

2. Shell Programming and Scripting

How to put delimiters in text files after fix characters?

Hi , i have a text file in which i want to put delimiters after certain characters ( fix),. like put a delimiter (any like ,) after 1-3 character than 4 than 5 than 6-17 ..... files looks like this (original)... (8 Replies)
Discussion started by: anamdev
8 Replies

3. UNIX for Dummies Questions & Answers

Text order

Hello unix.com I have a large text file in this format: merali guzman 34 vernon st 304 hartford CT Connecticut 6106 012-233-232 Working 13/14 100$ Morgan Dvorak 5670 Echo Road Excelsior MN Minnesota 5331 000-000-123 Sleeping 15/17 220$ How can... (1 Reply)
Discussion started by: galford
1 Replies

4. Shell Programming and Scripting

Print text between delimiters IF it contains a certain term...

So I'm racking my brain on appropriate ways to solve a problem that once fixed, will solve every problem in my life. Its very easy (for you guys and gals) I'm sure, but I can't seem to wrap my mind around the right approach. I really want to use bash to do this, but I can't grasp how I'm going to... (14 Replies)
Discussion started by: eh3civic
14 Replies

5. Shell Programming and Scripting

Fetch the rows with match string on a fixed lenth text file - NO delimiters

Hi I am trying to fetch the rows with match string "0000001234" Input file looks like below: 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1... (6 Replies)
Discussion started by: nareshk
6 Replies

6. AIX

Print text between two delimiters

Hi, Can somebody help me with the below situation, Input File, ======== 2007_08_07_IA-0100-014_(MONTHLY).PDF 2007_08_07_IA-0100-031_(QUARTERLY)(RERUN).PDF 2008-02-28_KR-1022-003_(MONTH)(RERUN)(REC1).CSV Required output, ============ MONTHLY QUARTERLY MONTH ... (15 Replies)
Discussion started by: sravicha
15 Replies

7. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

8. Shell Programming and Scripting

Ascending order within text

I appreciate all the help that I've already received but am running into one problem. I can find how to add something before a file with ascending numbers but not like this. I basically have a file that looks like this: 100 101 102 103 104 I need to add the following before each line with... (5 Replies)
Discussion started by: kerpm
5 Replies

9. UNIX for Advanced & Expert Users

extract text b/w two delimiters

I have an input file which looks like " @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql... (6 Replies)
Discussion started by: dowsed4u8
6 Replies

10. Shell Programming and Scripting

Order text display not correct.

My shell script below for import data to Oracle it run okay. but the text display not correct follow order command executed. =========================Shell Script code================= #!/bin/sh #directory = ${1-'pwd'} #run import data with SQLLoader runSQLLoader() { ... (2 Replies)
Discussion started by: raccsdl
2 Replies
Login or Register to Ask a Question