Remove ":" and join lines in outline file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove ":" and join lines in outline file
# 1  
Old 11-20-2010
Remove ":" and join lines in outline file

I have a vim outliner file like this:

PHP Code:
Title   
        title 2 
                
:Testing now
                
:testing 2
                
:testing 3
        title 3 
                
:testing
                
:ttt
                
:ttg 
Is there a way to use a script or command to remove the ":" in front of the the text blocks and join these lines to give this output?

PHP Code:
Title   
        title 2 
                Testing now testing 2 testing 3
        title 3 
                testing ttt ttg 
# 2  
Old 11-20-2010
Try this,
Code:
 awk '{if(/:/) {sub(/:/,"");printf "%s",$0}else{printf "\n%s\n",$0}} END {print "\n"}' inputfile

# 3  
Old 11-20-2010
Try this:
Code:
awk '/:/{if(s){$1=$1};s=s?s FS $0:$0; next}
s{gsub(":", "", s); print s; s=""}1
END{if(s)gsub(":", "", s);print s}
' file

This User Gave Thanks to Franklin52 For This Post:
# 4  
Old 11-20-2010
Try...
Code:
 
awk '{ORS=RS}/:/{sub(/:/,"");ORS=" "}1' infile

# 5  
Old 11-20-2010
Quote:
Originally Posted by Franklin52
Try this:
Code:
awk '/:/{if(s){$1=$1};s=s?s FS $0:$0; next}
s{gsub(":", "", s); print s; s=""}1
END{if(s)gsub(":", "", s);print s}
' file

Thanks for the suggestions! This works perfectly as it also removes the extra whitespace between the words.
# 6  
Old 11-20-2010
Code:
awk 'END{f(s)}function f(s){if(s)gsub(":",x,s);print s}/:/{if(s){$1=$1};s=((s)?s FS:x)$0;next}s{f(s);s=""}1' file

A spin-out of Franklin solution
# 7  
Old 11-20-2010
Code:
awk -F: '/:/{p=(p)?p OFS $2:$1$2;next}p{print p,p=x}1;END{print p}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

5. Shell Programming and Scripting

Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi, I am on a Solaris8 machine If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error" ...or Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great. ****************** ... (3 Replies)
Discussion started by: andy b
3 Replies

6. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

7. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

8. 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

9. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

10. Shell Programming and Scripting

join two lines when the second line contains "US DOLLAR"

I want to join two lines together when the second line contains "US DOLLAR". How to do that with sed? Original file: # cat testdata Sep. 24, 2005 Sep. 26, 2005 PHARMA PLUS DRUGMART 1149 $5.85 Sep. 25, 2005 Sep. 27, 2005 99 RESTAURANT #015 $11.00 US DOLLAR @ 1.203636 $13.24 ... (2 Replies)
Discussion started by: powah
2 Replies
Login or Register to Ask a Question