Appending line ending with '}" to new line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending line ending with '}" to new line
# 1  
Old 08-13-2007
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  
Old 08-13-2007
Try

Code:
tr '}' '\n' < your_file| tr -d '"{'

or
Code:
cat your_file | tr '}' '\n' | tr -d '"{'

# 3  
Old 08-13-2007
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 03:07 AM..
# 4  
Old 08-13-2007
Thanks lorcan, it works beautifully. Wish i were as good as you guys. Smilie
Thanks again
# 5  
Old 08-13-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work. I'm not very good at scripting, so bear with me please. Working on Linux RHEL I've been able to filter and edit and clean up using sed, but I have a problem with moving lines. ... (9 Replies)
Discussion started by: rex007can
9 Replies

3. UNIX for Dummies Questions & Answers

How to get last word from a line ending with "/" in Unix

Hello All, I have a scenario to read a file containing text like this:(say file name is Dummy.txt) /home/abc/test1/ | file1 /home/abc/test2/ | file2 I used a variable to store the content from file like this (say for line1): File=`head -1 Dummy.txt | cut -f1 -d "|"` Dir=`head -1 Dummy.txt... (2 Replies)
Discussion started by: Quesemail
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Appending the first word of each line to the end of each line

Hi Experts, Am relatively new to shell programming so would appreciate some help in this regard. I am looking at reading from a file, line by line, picking the first word of each line and appending it to the end of the line. Any suggestions? INPUT FILE - 3735051 :... (7 Replies)
Discussion started by: hj007
7 Replies

6. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

7. Shell Programming and Scripting

SED or AWK "append line to the previous line"

Hi, How can I remove the line beak in the following case if the line begin with the special char “;”? TEXT Text;text ;text Text;text;text I want to convert the text to: Text;text;text Text;text;text I have already tried to use... (31 Replies)
Discussion started by: research3
31 Replies

8. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

9. Shell Programming and Scripting

Appending a line in a file after a particular line

Hello, I have got a C file in which I would like to add an include statement of my own. There are already a few include statements and mine should come right after the last existing one (to be neat). With grep I can get the lines containing the word 'include' and I guess I should feed the... (7 Replies)
Discussion started by: maxvirrozeito
7 Replies

10. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies
Login or Register to Ask a Question