Delete between two words


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete between two words
# 1  
Old 09-23-2014
Delete between two words

Code:
So;C951;1;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=C5951,ManagedElement=1,vsDaFunction=1;473;12;EEE
So;C951;2;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=L5921,ManagedElement=1,vsDaFunction=4;481;12;EEE

Output:-

So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE

Output 2:-

So;C951;1;2;0;100;true;473;12;EEE
So;C951;4;2;0;100;true;481;12;EEE

# 2  
Old 09-23-2014
What have you tried?
# 3  
Old 09-23-2014
Read about sed command.
# 4  
Old 09-23-2014
Quote:
Originally Posted by pareshkp
Code:
So;C951;1;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=C5951,ManagedElement=1,vsDaFunction=1;473;12;EEE
So;C951;2;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=L5921,ManagedElement=1,vsDaFunction=4;481;12;EEE
 
Output:-
 
So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE
 
Output 2:-
 
So;C951;1;2;0;100;true;473;12;EEE
So;C951;4;2;0;100;true;481;12;EEE

Hello pareshkp,

Following may help.

1st requirement solution:
Code:
awk -F";" '{gsub(/.*\=/,X,$(NF-3));print}' OFS=";"  Input_file

Output will be as follows.
Code:
So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE

2nd requirement solution:
Code:
awk -F";" '{gsub(/.*\=/,X,$(NF-3));{$3=$(NF-3);$(NF-3)="\b"};print}' OFS=";"  Input_file

Output will be as follows.
Code:
So;C951;1;2;0;100;true;473;12;EEE
So;C951;4;2;0;100;true;481;12;EEE

EDIT: Sorry corona688 I haven't seen your post seems we were writing on almost same time.

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-24-2014 at 01:47 AM.. Reason: Adding comment about post + edited 2nd requirement solution Thanks to Akshay
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-23-2014
Thanks A lot Buddy Smilie
# 6  
Old 09-23-2014
Code:
$ awk  '{n=split($8,A,/=/); $8 = mode ? A[n] : "\b"; $3 = mode ? $3 : A[n] }1' FS=';' OFS=';' mode='0' file
So;C951;1;2;0;100;true;473;12;EEE
So;C951;4;2;0;100;true;481;12;EEE

Code:
$ awk  '{n=split($8,A,/=/); $8 = mode ? A[n] : "\b"; $3 = mode ? $3 : A[n] }1' FS=';' OFS=';' mode='1' file
So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE

This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 09-23-2014
Quote:
Originally Posted by Akshay Hegde
Code:
$ awk  '{n=split($8,A,/=/); $8 = mode ? A[n] : "\b"; $3 = mode ? $3 : A[n] }1' FS=';' OFS=';' mode='0' file
So;C951;1;2;0;100;true;473;12;EEE
So;C951;4;2;0;100;true;481;12;EEE

Code:
$ awk  '{n=split($8,A,/=/); $8 = mode ? A[n] : "\b"; $3 = mode ? $3 : A[n] }1' FS=';' OFS=';' mode='1' file
So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE

Hello Akshay,

Nice code Smilie, in 2nd code I guess there is no need to use $3 part in this code, it may work as follows too.

Code:
awk  '{n=split($8,A,/=/); $8 = mode ? A[n] : "\b"; }1' FS=';' OFS=';' mode='1'  Input_file

Output will be as follows.
Code:
So;C951;1;2;0;100;true;1;473;12;EEE
So;C951;2;2;0;100;true;4;481;12;EEE

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete some words

hi, i have a fasta file like this: >contig00003 length=363 numreads=45 gene=isogroup00001 status=it_thresh GATTTTTTACCCTGGGAGTGAGGAGGACGAGGTTGAGGATGAAGAAAAGAGAAAGATGAAGAGGTTGAGGATGTT GTAGTCGGCGGTGGAATTAGGGGGAGCCGGCGAGCCCAAGTATTTTGCAGAGGTGTCTTCATCATCCAAACAACA... (3 Replies)
Discussion started by: the_simpsons
3 Replies

2. UNIX for Dummies Questions & Answers

Delete all words not containing letter /s/

I have a word file that looks like: pens binder spiral user I want to delete all the words without the letter /s/, so output looks like: pens spiral user I tried using sed: sed '//d' infile.txt > out.txt (5 Replies)
Discussion started by: pxalpine
5 Replies

3. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

4. Shell Programming and Scripting

Using Sed to Delete Words in a File

This is a Nagios situation. So i have a list of servers in one file called Servers.txt And in another file called hostgroups.cfg, i want to remove each and every one of the servers in the Servers.txt file. The problem is, the script I wrote is having a problem removing the exact servers in... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. Shell Programming and Scripting

Delete between two words

Hi, I wanted to delete data between two words. Input: I read gihoihsahkjlk write goal hard read hsakdjhkh write work read hlkhlkhlkh write Desired Output: I write goal hard write work write We have to replace the data that comes between 'read' and 'write' with... (3 Replies)
Discussion started by: mahish20
3 Replies

6. Shell Programming and Scripting

Need to delete words in a file

Hi All, I have an input file a.txt which contains the following :: 08-08-09 1:00 PM 763763762 f00_unix1_server.txt i Just need to delete all the words which is before f Output :: f00_unix1_server.txt Thanks (4 Replies)
Discussion started by: raghav1982
4 Replies

7. UNIX for Dummies Questions & Answers

how can i delete words based on search

hi, I have a doubt. how we can remove few words based on search. here im specifying my requirement with example. ALL the words should delete between two words ... those words will ends ** EX : cat infile.txt "HI",ob1**,ob2,ob3,ob4**,ob5,ob6 OUTPUT... (2 Replies)
Discussion started by: spc432
2 Replies

8. UNIX for Advanced & Expert Users

How to delete first 10 words from file

Hi, Could you please let me know, how to delete first 10 words from text files using vi? 10dw will delete it from current line, how to do it for all the lines from file? Thanks (6 Replies)
Discussion started by: sentak
6 Replies

9. UNIX for Dummies Questions & Answers

sed [delete everything between two words]

Hi, I have the following codes below that aims to delete every words between two pattern word. Say I have the files To delete every word between WISH_LIST=" and " I used the below codes (but its not working): #!/bin/sh sed ' /WISH_LIST=\"/ { N /\n.*\"/ {... (3 Replies)
Discussion started by: Orbix
3 Replies

10. Shell Programming and Scripting

Delete lines that contain 3 or more words?

How can I delete lines that contain 3 or more words? I have a file, old.txt, that has multi-word phrases in it and I want to remove the lines with 3 words or more and send the output to new.txt. I've tried the following using sed but it doesn't seem to work: sed '/(\b\w+\b){3,}/d' old.txt >... (5 Replies)
Discussion started by: revax
5 Replies
Login or Register to Ask a Question