Collating strings using sed

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Collating strings using sed
# 1  
Old 11-12-2001
Question Collating strings using sed

I am trying to work out how to collate a string in sed.
The format is...
01 R W R D
But i want it to sort like so...
i have tried regular expressions on this but because their are many different ways this string could appear, it is not working out.
Does anyone know a method of doing this?
# 2  
Old 11-12-2001
What are the different ways the string could appear? It's not clear to me what you're trying to do. Maybe some examples would help.
# 3  
Old 11-13-2001
OK I have a series of strings like this...
01 R W D R
02 W D R R
03 R W R R

But i want it to look like this...
01 R R D W
02 R R D W
03 R R R W

so in other words I want it to place all the R's at the front followed by the D's and then followed by the W's.

So far i have worked out a long winded method of doing this but I'm sure there is a shorter way.
Here is my example...
s/W R/R W/g
s/D R/R D/g
s/W D/D W/g
but this only does this to the line once. is there a method i can make this loop in sed?

Help please Smilie
# 4  
Old 11-13-2001
sed isn't a great tool for this problem. I would use ksh:

#! /usr/bin/ksh
while read number rest ; do
       set $rest
       set -s
       echo $number $@
exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed find 2 strings and replace one

Hi Everyone, I want to find this 2 strings in a single line a file and replace the second string. this is the line i need to find <param name="user" value="CORE_BI"/> find user and CORE_BI and replace only CORE_BI with admin so finally the line should look like this. <param... (5 Replies)
Discussion started by: shajay12
5 Replies

2. Shell Programming and Scripting

Matching only the strings I provide - sed

Hello.. I am currently learning sed and have found myself in some trouble.. I wrote this command: sed -ne 's/*\(\{2\}*\{2\}*\{2\}*\).*\(\{2\}*\{2\}*\{2\}*\).*/\1\2/p' and some of the output i get is : ->stockholm->paris<-stockholmpi<-tokyo->paris<-stockholmpi... (8 Replies)
Discussion started by: jozo95
8 Replies

3. Shell Programming and Scripting

Delete 2 strings from 1 line with sed?

Hi guys, I wonder if it's possible to search for a line containing 2 strings and delete that line and perhaps replace the source file with already deleted line(s). What I mean is something like this: sourcefile.txt line1: something 122344 somethin2 24334 45554676 line2: another something... (6 Replies)
Discussion started by: netrom
6 Replies

4. Shell Programming and Scripting

sed to extract all strings

Hi, I have a text file containing 2 lines as follows: I'm trying to extract all the strings following an "AME." The output would be as follows: BUSINESS_UNIT PROJECT_ID ACTIVITY_ID RES_USER1 RESOURCE_ID_FROM ANALYSIS_TYPE BI_DISTRIB_STATUS BUSINESS_UNIT PROJECT_ID ACTIVITY_ID... (5 Replies)
Discussion started by: simpletech369
5 Replies

5. Shell Programming and Scripting

Using sed to replace strings if NOT found

Dear expert, I need an urgent help. I would like to update my /etc/ntp.conf file using sed. 1) if script find this string "" then add the lone below #server 2) is script find this string "fudge stratum 10" then add #fudge stratum 10 ... (7 Replies)
Discussion started by: lamoul
7 Replies

6. Shell Programming and Scripting

Using sed to replace two different strings?

Hey everyone! Simple question - I am trying to use sed to replace two different strings. As it stands I can implement this as: sed -i 's/TIMEOUT//g' sed -i 's/null//g' And it works. However, is it possible to shrink that down into a single command? Will there be any performance benefits? (3 Replies)
Discussion started by: msarro
3 Replies

7. Shell Programming and Scripting

Comparing strings with sed

Input: The the the the Output: not-same same What would be the sed command to do this? (7 Replies)
Discussion started by: cola
7 Replies

8. Shell Programming and Scripting

Remove strings within range using sed

Hey folks I have a big file that contains junk data between the tags <point> and </point> and I need to delete it (including `<point>' and `</point>'). i.e. a = 1 <point> 123123 2342352 234231 234256 </point> print a needs to become a = 1 print a I'm certain that this is a... (10 Replies)
Discussion started by: ksk
10 Replies

9. Shell Programming and Scripting

Replace Strings with sed or awk

Hello i need some help with the usage of sed. Situation : 2 textfiles, , file.out In the first textfile which is called are the words for the substitution. Every word is in a new-line like : Firstsub Secondsub Thridsub ... In the second textflie wich is called file.out is... (5 Replies)
Discussion started by: Kingbruce
5 Replies

10. Shell Programming and Scripting

sed replaces all matched strings!!!

hi sed -e '/<group>/!s/group\(.*\)/group\: files compat/' /etc/nsswitch.conf returns group: files compat netgroup: files compat How to prevent changing netgroup entry?? thank you (1 Reply)
Discussion started by: melanie_pfefer
1 Replies
Login or Register to Ask a Question