Removing ONLY UNIQUE blank spaces with sed?

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Removing ONLY UNIQUE blank spaces with sed?
# 1  
Old 06-16-2014
Removing ONLY UNIQUE blank spaces with sed?

Hi, I have data that looks similar to this:
In which the sentences are written horizontally and the beginning of a sentence is indicated by a 1 in the first column and the number increments until the last item of the sentence. The end of the sentence and the beginning of the next is then indicate by two white lines that separate them.

However, my data has some single white lines within the sentence which is causing problems. Is there a sed or a grep that will remove ONLY those instances of SINGLE white lines, leaving in place all of the double white lines that indicate the sentence change?

Please let me know if you can help.


Code:
1       ...     -       ...     :       -       0       ROOT    -       -


1       This    -       this    DT      -       3       NMOD    -       -
2       concerns        -       concern NNS     -       3       NMOD    -      -
3       finger  -       finger  NN      -       0       ROOT    -       -

4       ,       -       ,       ,       -       3       P       -       -
5       or      -       or      CC      -       3       CC      -       -
6       rather  -       rather  RB      -       8       NMOD    -       -
7       the     -       the     DT      -       8       NMOD    -       -
8       lack    -       lack    NN      -       3       COORD   -       -
9       of      -       of      IN      -       8       NMOD    -       -
10      finger  -       finger  NN      -       9       PMOD    -       -

11      .       -       .       SENT    -       0       ROOT    -       -

1       And     -       and     CC      -       3       CC      -       -
2       tattoo  -       tattoo  NN      -       3       DEP     -       -

3       .       -       .       SENT    -       0       ROOT    -       -


1       Here    -       here    RB      -       6       ADV     -       -
2       the     -       the     DT      -       5       NMOD    -       -
3       highlighted     -       highlight       VVN     -       5       NMOD   --
4       nouns   -       noun    NNS     -       6       SBJ     -       -
5       are     -       be      VBP     -       0       ROOT    -       -
6       not     -       not     RB      -       6       VMOD    -       -
7       for     -       for     IN      -       8       ADV     -       -
8      number  -       number  NN      -       9       PMOD    -       -
9      in      -       in      IN      -       10      ADV     -       -
10      any     -       any     DT      -       13      NMOD    -       -
11      way     -       way     NN      -       11      PMOD    -       -


The desired result is as follows:


Code:
1       ...     -       ...     :       -       0       ROOT    -       -


1       This    -       this    DT      -       3       NMOD    -       -
2       concerns        -       concern NNS     -       3       NMOD    -      -
3       finger  -       finger  NN      -       0       ROOT    -       -
4       ,       -       ,       ,       -       3       P       -       -
5       or      -       or      CC      -       3       CC      -       -
6       rather  -       rather  RB      -       8       NMOD    -       -
7       the     -       the     DT      -       8       NMOD    -       -
8       lack    -       lack    NN      -       3       COORD   -       -
9       of      -       of      IN      -       8       NMOD    -       -
10      finger  -       finger  NN      -       9       PMOD    -       -
11      .       -       .       SENT    -       0       ROOT    -       -


1       And     -       and     CC      -       3       CC      -       -
2       tattoo  -       tattoo  NN      -       3       DEP     -       -
3       .       -       .       SENT    -       0       ROOT    -       -


1       Here    -       here    RB      -       6       ADV     -       -
2       the     -       the     DT      -       5       NMOD    -       -
3       highlighted     -       highlight       VVN     -       5       NMOD   --
4       nouns   -       noun    NNS     -       6       SBJ     -       -
5       are     -       be      VBP     -       0       ROOT    -       -
6       not     -       not     RB      -       6       VMOD    -       -
7       for     -       for     IN      -       8       ADV     -       -
8      number  -       number  NN      -       9       PMOD    -       -
9      in      -       in      IN      -       10      ADV     -       -
10      any     -       any     DT      -       13      NMOD    -       -
11      way     -       way     NN      -       11      PMOD    -       -

# 2  
Old 06-16-2014
Try
Code:
awk 'NF==0 {next} $1==1 && NR>1 {print "\n"}1' file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

2. UNIX for Dummies Questions & Answers

Remove blank spaces

Dear Masters, I want to remove all lines with blank spaces input file: a|abc|0|1 a|abc|2|3 b||3|5 c|def||7 d|def|0|1 Expected: a|abc|0|1 a|abc|2|3 d|def|0|1 I did this awk -F'|' '!/^$/' input (4 Replies)
Discussion started by: radius
4 Replies

3. Shell Programming and Scripting

Removing blank/white spaces and special characters

Hello All , 1. I am trying to do a task where I need to remove Blank spaces from my file , I am usingawk '{$1=$1}{print}' file>file1Input :- ;05/12/1990 ;31/03/2014 ; Output:- ;05/12/1990 ;31/03/2014 ;This command is not removing all spaces from... (6 Replies)
Discussion started by: himanshu sood
6 Replies

4. Solaris

Removing blank spaces

Hi , I want to go out of vi editor temporarily and execute a command in command prompt and again going back to the editor . Is it possible . Any help on this is really helpful. 1. Need to open vi 2. Temporarily come out and execute a command and go back to vi editor (6 Replies)
Discussion started by: rogerben
6 Replies

5. Shell Programming and Scripting

removing blank spaces in a script

Hi I am writing a shell to run sqlplus scripts. i found a issue in my scripts that oracle will not spool a file if there is blank spaces in the word like /backup dir/scriptrelease/1_DDL or /backupdir/script release/2_DDL can we write some thing in the shell to make "/backup dir" to... (1 Reply)
Discussion started by: srichunduru
1 Replies

6. Shell Programming and Scripting

how to read blank spaces

hi i have a file which store some data.the contents of my file is data1:data2 data3:data4 i have a script which read this file correct="$(cat /root/sh | cut -d: -f1)" i used this syntax..please help me which syntax is used to read blank spaces.and then remove it and after that how to read... (1 Reply)
Discussion started by: shubhig15
1 Replies

7. UNIX for Dummies Questions & Answers

Removing blank spaces from text files in UNIX

Hello, I am an super newbie, so forgive my sheer ignorance. I have a series of text files formatted as follows (just showing the header and first few lines): mean_geo mean_raw lat lon 0.000 0 -70.616 163.021 0.000 0 -70.620 163.073 0.000 ... (8 Replies)
Discussion started by: vtoniolo
8 Replies

8. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

9. Shell Programming and Scripting

Handling blank spaces

Hi, I am trying to replace a specific column values in a csv file with double quotes when I am find embedded spaces with in the fields. Example: SNO,NAME,ZIPCODE,RANK,SEX,ADDRESS 1,Robert,74538,12,34, M,Robert Street, NY 2,Sam,07564,13,M,12 Main Ave, CA 3,Kim, Ed,12345,14,M,123D ,... (1 Reply)
Discussion started by: techmoris
1 Replies

10. Shell Programming and Scripting

Removing blank spaces from a file?

Guys, I need some help... how can I remove the blank spaces between the lines below? (between the date and the hour fields) 21/05/07 00:05:00 99 21/05/07 00:10:01 99 21/05/07 00:15:00 99 21/05/07 00:20:00 99 21/05/07 00:25:00 99 I want to make the file... (4 Replies)
Discussion started by: dfs
4 Replies
Login or Register to Ask a Question