The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
Appending a line in a file after a particular line maxvirrozeito Shell Programming and Scripting 7 12-12-2007 01:58 PM
Sed - Appending a line with a variable on it eltinator Shell Programming and Scripting 4 07-30-2007 09:15 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-21-2007 01:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-13-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
Appending line ending with '}" to new line

Hello masters.

I have a rather simple problem but its been killing me. I have a file "x" with only 1 line inside it. The line looks something like
Quote:
{"01"|"15131"|"2506"|""}{"01"|"15651"|"2506"|""}{"01"|"20831"|"2506"|""}{"01"|"24811"|"2506"|""}{"01 "|"24812"|"2506"|""}{"01"|"24813"|"2506"|""}{"01"|"1
"}{"01"|"15032"|"2506"|""}{"01"|"9112"|"2506"|""}{"01"|"9023"|"2506"|""}{"01"|"9032"|"2506"|""}{"01" |"25137"|"2506"|""}{"01"|"25138"|"2506"|""}{"01"|"28430"|"
|"2053"|"12050"|"205"}{"01"|"2361"|"12050"|"236"}{"01"|"2362"|"12050"|"236"}{"01"|"2052"|"12050"|"20 5"}{"01"|"173"|"12050"|"17"}{"01"|"511"|"12050"|"51"}{"02"
|""}{"02"|"1422"|"2504"|""}{"02"|"1423"|"2504"|""}{"02"|"4746"|"2504"|""}{"02"|"4747"|"2504"|""}{"02 "|"4748"|"2504"|""}{"02"|"1461"|"2504"|""}{"02"|"1462"|"25
1463"|"2504"|""}{"02"|"1431"|"2504"|""}{"02"|"1432"|"2504"|""}{"02"|"1433"|"2504"|""}{"03"|"48441"|" 4500"|""}
Now this is only part of the line. Its actually about 4000 characters. What i need to do is whenever there is a "}", i need to append the next characters into a new line. Ive tried cracking my head with sed but cant find the correct command. Pls help. I need something that will look like

01|15131|2506
01|15651|2506
01|20831|2506
01|24811|2506

Pls HELP !

Thanks.
Sara
  #2 (permalink)  
Old 08-13-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Try

Code:
tr '}' '\n' < your_file| tr -d '"{'
or
Code:
cat your_file | tr '}' '\n' | tr -d '"{'
  #3 (permalink)  
Old 08-13-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Or,

Code:
sed -e "s/}/}\n/g" in.txt
To get the output you are looking for, i.e.
Code:
01|15131|2506
01|15651|2506
01|20831|2506
01|24811|2506
use

Code:
sed -e "s/}/}\n/g" -e "s/[\"{}]//g" -e "s/|\n/\n/g" in.txt

Last edited by vino; 08-13-2007 at 02:07 AM..
  #4 (permalink)  
Old 08-13-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
Thanks lorcan, it works beautifully. Wish i were as good as you guys.
Thanks again
  #5 (permalink)  
Old 08-13-2007
aismann aismann is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 37
Thanks vino. But its giving me an output like
Quote:
{"01"|"15131"|"2506"|""}n{"01"|"15651"|"2506"|""}n{"01"|"20831"|"2506"|""}n{"01"|"24811"|"2506"|""}n {"01"|"24812"|"2506"|""}n{"01"|"24813"|"2506"|""}n{"01"|"15661"|"2506"|""}n{"01"|"15032"|"2506"|""}n {"01"|"9112"|"2506"|""}n{"01"|"9023"|"2506"|""}n{"01"|"9032"|"2506"|""}n{"01"|"25137"|"2506"|""}n{"0 1"|"25138"|"2506"|""}n{"01"|"28430"|"2506"|""}n{"01"|"2053"|"12050"|"205"}n{"01"|"2361"|"12050"|"236 "}n{"01"|"2362"|"12050"|"236"}n{"01"|"2052"|"12050"|"205"}n{"01"|"173"|"12050"|"17"}n{"01"|"511"|"12 050"|"51"}n{"02"|"1421"|"2504"|""}n{"02"|"1422"|"2504"|""}n{"02"|"1423"|"2504"|""}n{"02"|"4746"|"250 4"|""}n{"02"|"4747"|"2504"|""}n{"02"|"4748"|"2504"|""}n{"02"|"1461"|"2504"|""}n
however i already have the solution. Thanks guys.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0