SED problem - Novice question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED problem - Novice question
# 1  
Old 02-21-2012
SED problem - Novice question

Hi,
Need some help with a sed command I have butchered together (with help from this forum):
I have a script that has the following output (a small example of the full file):
example.txt
Code:
092F 1639163_Cluster01_Prod
0522 1639163_Cluster02_Prod
08C2 1639163_Cluster07_Prod
0957 1639163_Cluster07_Prod
1762 1024477_Cluster07_Prod
1767 1024477_Cluster07_Prod
176C 1024477_Cluster07_Prod
1771 1024477_Cluster07_Prod
1776 1024477_Cluster07_Prod
1EDC 1639163_Cluster07_Prod
1EE4 1639163_Cluster07_Prod
07F0 2048953_Cluster11_Prod
0807 1228838_Cluster11_Prod
175C 1229372_Cluster11_Prod
1B68 1024477_Cluster11_Prod
1E87 1639163_Cluster11_Prod
1D2B 1010831_SRV93012
1D6A 1045688_SRV93013
143E  34856 RS6PUNI01_Cluster
143F  34856 RS6PUNI01_Cluster
1440  34856 RS6PUNI01_Cluster
1441  34856 RS6PUNI01_Cluster
1442  34856 RS6PUNI01_Cluster
1443  34856 RS6PUNI01_Cluster
0F70 1639163_CLUSTER50_DR_07
0F78 1639163_CLUSTER50_DR_07
0F80 1639163_CLUSTER50_DR_07
0215 718125 CLUSTER51_DR_08
02FD 504128 CLUSTER51_DR_08
0305 504128 CLUSTER51_DR_08

As an example there are underscores between the middle number column and the server names:
Code:
1EE4 1639163_Cluster07_Prod
07F0 2048953_Cluster11_Prod
0F80 1639163_CLUSTER50_DR_07

There should be no underscore, just a space between the names e.g:
Code:
07F0 2048953 Cluster11_Prod
0F80 1639163 CLUSTER50_DR_07

I have the following sed command:
Code:
'sed 's/_\([[:alpha:]]*[0-9][0-9]*\)/ \1/'

this sed command has corrected the problem almost for all the naming problems I have.
However for the server names that have "DR" in them I get the following output:
Code:
01FB 1024477 CLUSTER50_DR_07
0200 1024477 CLUSTER50_DR_07
02ED 504128 CLUSTER50_DR 07
02F5 504128 CLUSTER50_DR 07
030D 504128 CLUSTER50_DR 07

I could run another SED command that replaces the "_DR " with "_DR_" but wondered if there was any better way of adapting my existing SED command.
Thanks in advance.
Col
# 2  
Old 02-21-2012
Hi, try:
Code:
sed 's/[_ \t][_ \t]*/ /2' infile


Last edited by Scrutinizer; 02-21-2012 at 08:44 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-21-2012
Code:
sed 's/\([^ ]* [0-9]*\)_/\1 /' inputfile

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

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can someone help me create this script(I'm a novice)

I've literally been handed this assessment for my course and the lecturer is of no help at all he's taught us virtually nothing would anyone be able to show me how the following script should look on Linux - For this assignment you have to write a Linux Shell Script which will allow a user to... (1 Reply)
Discussion started by: Andy_cyber
1 Replies

2. Programming

Novice in C needs help

Guys can you help me ? I'm novice in C but I have a lot of will to master C. Each gurney starts with first step O.K. My problem is to compare two integers entered by user I know how to set up conditions and problem is how to print correct value (grater number) // This program... (5 Replies)
Discussion started by: solaris_user
5 Replies

3. Shell Programming and Scripting

sed question from novice

My pipe delimited file is coming over with spurious “\” characters inserted into some alpha fields, which is causing the records to be split into 2. Eg Abc|def|10/11\ AAAA|xyz Lmn|opq|10/11BBBB|xyz etc etc I am having to go into vi, then enter / \ to... (5 Replies)
Discussion started by: malts18
5 Replies

4. Shell Programming and Scripting

Need help with a little script - novice

I am just learning unix and need some help. I am trying to display all of the files I have modified within the last 24 hours and sort them from the most recently modified. I can't figure it out.. I've been using a lot of ls and find commands. Here are some things I've tried: find . -mtime -1 |... (4 Replies)
Discussion started by: mredwin3
4 Replies

5. UNIX for Dummies Questions & Answers

NEW to Unix (novice)

Heya all Im just reading up on the solaris o/s and unix and i just have the following qustions 1) is the solaris o/s the same as Unix if not how are they different - i.e. are they different operating systems? 2) Can the Unix be loaded from CD without affectin windows o/s just like linux... (2 Replies)
Discussion started by: new214
2 Replies

6. Solaris

New to solaris (novice)

Heya all Im just reading up on the solaris o/s and have a few questions regarding it: 1) is the solaris of free to use/download? if yes where? 2) Can the solaris o/s be loaded from CD without affectin windows o/s just like linux can? 3) what are the hardware requirements for using... (2 Replies)
Discussion started by: new214
2 Replies

7. Shell Programming and Scripting

Problem for novice

Hi, I am observing a problem wiht my script. I tokk that part and executed from the command prompt. Below is the command the error. CAn any one suggest what should be done here. if ($cnt -lt $maxcnt) then echo deepu fi ksh: 0: not found Thanks in advance (16 Replies)
Discussion started by: deepaksamuel
16 Replies

8. Linux

Hi I M Novice User

hi everyone i m a novice user . just want to know how to use this website and also learn unix from the basics. can any one help me please.... (2 Replies)
Discussion started by: MSK
2 Replies

9. Programming

novice student needs help

Help! I am very stuck!!! I have to produce a practical implementation of ONC RPC for an assignment and I do not know where to start. I hve done much searching on sun's site but everything is too complicated for someone with my limited knowledge. I only know the very basic unix commands and have... (1 Reply)
Discussion started by: karen79
1 Replies

10. Linux

Question From a Novice

HELLO GUYS, How u all guys doing?Recently I brought a system and installed Red Hat Linux in it. I have also got a network card. My question is can i connect NIC to my system and use it as a client? I really don't want to buy another system. I want to use this computer/system both as server and... (0 Replies)
Discussion started by: cyno
0 Replies
Login or Register to Ask a Question