Sorting a string


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Sorting a string
# 1  
Old 01-12-2006
Sorting a string

Hello all, I have some 20-digit strings - say 1234567890abcdefghij
I want to remove the 3rd and then the 11-18th strings, but leave a space between the two resulting strings
eg "3 abcdefgh"

I only know how to use "cut", does anyone know any way I can do this? All these strings are in the same file.


Thanks
Khoom

Last edited by Khoomfire; 01-12-2006 at 10:35 AM..
# 2  
Old 01-12-2006
this is for sure hard-coded

anyway it's just a try

Code:
echo 1234567890abcdefghij | sed -e 's/\(..\)\(.\)\(.......\)\(.*\)/\2 \4/'

# 3  
Old 01-12-2006
Code:
[~/temp]$ cat khoom.sh 
#! /bin/sh
VAL=1234567890abcdefghij
echo ${VAL:2:1} ${VAL:10}
[~/temp]$ ./khoom.sh 
3 abcdefghij
[~/temp]$

# 4  
Old 01-12-2006
Hi guys,
sorry, but I amended the request at some point, but both alternatives didn't work.

Cheers
Khoom
# 5  
Old 01-12-2006
Quote:
Originally Posted by Khoomfire
Hi guys,
sorry, but I amended the request at some point, but both alternatives didn't work.

Cheers
Khoom
could you please quote your sample input and the output that you are receiving which deviates the required output, so that it would be easier to look into ?
# 6  
Old 01-12-2006
Quote:
Originally Posted by matrixmadhan
could you please quote your sample input and the output that you are receiving which deviates the required output, so that it would be easier to look into ?
Hello Matrix,
your option is actually pretty much on course, but I modified my desired output after you helped. What you gave me will give me 3 abcdefghij, but I want 3 abcdefgh

Cheers
Ben
# 7  
Old 01-12-2006
Quote:
Originally Posted by Khoomfire
Hello all, I have some 20-digit strings - say 1234567890abcdefghij
I want to remove the 3rd and then the 11-18th strings, but leave a space between the two resulting strings
eg "3 abcdefghij"

I only know how to use "cut", does anyone know any way I can do this? All these strings are in the same file.


Thanks
Khoom
desired output as requested above : 3 abcdefghij

Quote:
your option is actually pretty much on course, but I modified my desired output after you helped. What you gave me will give me 3 abcdefghij, but I want 3 abcdefgh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help on Sorting

Hello Everyone, I need help here . I need to sort a file for one of my requirement , The file has to be sorted using a key with 4 columns. Sorting is working fine on those 4 columns but when the key is matching for many rows the other columns are also getting sorted which is not required . ... (11 Replies)
Discussion started by: richa_240889
11 Replies

2. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

3. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

string sorting in unix

Hi I need how to sort string characters for Example i have a file that contains this data example string "fan" but i want to display "afn" contained words "afn" is in sorted format for fan. File data faty gafny gaifny dafan gafnniunt O/p gafny gafnniunt (3 Replies)
Discussion started by: polineni
3 Replies

5. Shell Programming and Scripting

[Perl] Sorting an String-Array

Hi, i have a txtfile with the format <Nr>tab<word>tab<other stuff>new line and i want to sort the <word>-colum with a perl script. My textfile: <Nr>tab<word>tab<other stuff>new line 6807 die ART.Acc.Sg.Fem 6426 der ART.Gen.Sg.Fem 2 die ART.Nom.Sg.Fem 87 auf APPR.-- 486 nicht PTKNEG.--... (1 Reply)
Discussion started by: buckelede
1 Replies

6. Shell Programming and Scripting

Sorting

Let's say that I have a database that I call part ID. This database has the following grouping: Dart1=4 Dart2=8 Dart3=12 Fork1=68 Fork2=72 Fork3=64 Bike1=28 Bike2=24 Bike3=20 Car1=44 Car2=40 Car3=36 I want to write a program that would read this database and tell me when the... (19 Replies)
Discussion started by: Ernst
19 Replies

7. Shell Programming and Scripting

Sorting string with date and number

Hi, We have files coming in the system and we want to sort it in ascending order with date and sequence. The file pattern are inbound_crp_date_sequence.xml example we have file as below: inbound_crp_20100422_10.xml inbound_crp_20100422_2.xml inbound_crp_20100422_3.xml... (2 Replies)
Discussion started by: sreejitnair123
2 Replies

8. UNIX for Dummies Questions & Answers

sorting ASCII string containing numbers

I have the following output where I need to sort the second column numerically (starting with IBMULT3580-TD10 and ending in IBMULT3580-TD123) Drv DriveName 0 IBMULT3580-TD13 1 IBMULT3580-TD18 2 IBMULT3580-TD14 3 IBMULT3580-TD10 4 IBMULT3580-TD11 5 IBMULT3580-TD17 ... (8 Replies)
Discussion started by: GKnight
8 Replies

9. Shell Programming and Scripting

Perl: sorting by string

I have an array full of string values that need to be sorted, but if a value starts with (regex) 0^ it should be at the beginning of the array. Otherwise the array should be sorted normally using ascii sort. Please help me create the sub to pass to the sort function. (7 Replies)
Discussion started by: dangral
7 Replies

10. Shell Programming and Scripting

Sorting an address string

I'm in an introduction to Unix class and well I'm kind of stuck on one part of the lab for this week or shell scripts. Basically we're given a file named address.data and we're supposed to create a script to sort it according to zip code, last name, and first name (not at the same time of course).... (0 Replies)
Discussion started by: Minimum
0 Replies
Login or Register to Ask a Question