Need help for finding correct delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help for finding correct delimiter
# 1  
Old 06-27-2012
Need help for finding correct delimiter

I've a series of words in the format "abc0001d" till "abc1999d".

I would like to use delimiter to cut the word from abc0001s to two words:

abc00 and 01d. Help me in finding the correct delimiter to cut in desired way.
# 2  
Old 06-27-2012
Code:
 
$ echo "abc0001d" | awk '{print substr($0,1,5)}'
abc00
$ echo "abc0001d" | awk '{print substr $0,6,3)}'
01d

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 06-27-2012
With a space as delimiter:
Code:
echo "abc0001d" | sed 's/\(.....\)\(.*\)/\1 \2/'

# 4  
Old 06-27-2012
You can use cut character option to get the result
Code:
while read line
do
        firstFour=`echo $line|cut -c1-5`
         lastThree=`echo $line|cut -c6-8`
       echo "First Four= $firstFour"
         echo "Last Three= $lastThree"
done < file

# 5  
Old 06-27-2012
Code:
$ x=abc0001d
$ first=${x:0:5}
$ echo $first
abc00
$ second=${x:5:7}
$ echo $second
01d

# 6  
Old 06-27-2012
Another way,

Code:
$ a=abc0001d
$ echo ${a:0:5}
abc00
$ echo ${a:5}
01d


EDIT : Simultaneous posting. Same solution as above.
# 7  
Old 06-27-2012
Thanks for your help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

2. Shell Programming and Scripting

Finding delimiter

Hi, I need to find the field separator for the given files. Ex- abc.txt is "|" delimited file , when I give command the output should be "|" and that shud store it in another variable. This is same with csv files or any other delmited file. If I give the filename it shud give the... (1 Reply)
Discussion started by: Prashanth B
1 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

4. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

5. HP-UX

Finding the correct LUN

I am using hp ux 11.31 Our SAN storage is being presented from an IBM XIV. We have 3 HP servers (rx4640's), and the XIV has them setup in a cluster, so that when a disk is presented all 3 servers can see the new LUN. I'm setting up a new VM on one of the HP servers. I have allocated a 34Gb... (1 Reply)
Discussion started by: xtoverus1
1 Replies

6. Solaris

Help with finding correct log files

Lets say i have files like the following format :- R0001.log R0002.log ... ... R00011.log upto R000n.log, there are also a lot of text files with different names now how can i find these files with in a range, i can do "ls R000*.log" and it will show me all the R000*.log files but what... (2 Replies)
Discussion started by: oopsalion
2 Replies

7. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

8. Shell Programming and Scripting

finding correct directories

I have directories like V00R01,V00R02,V01R01,V01R02 in a directory where V is version and R is a release. basically I need to set base directory and current directory. Under a version there can be any number of releases and there can be number of versions also. V00R01...V00R50..so on also,... (2 Replies)
Discussion started by: vjasai
2 Replies

9. Shell Programming and Scripting

Please correct this

I have input file like this Input file: ABC|abc_etc_passwd XYZ|XYZ_etc_passwd zXY|XYZ_etc_passwd IJK|test_etc_passwd KLM|test_etc_passwd i want to do following in a loop. grep 'ABC' *abc_etc_passwd* grep 'XYZ' *XYZ_etc_passwd* grep 'ZXY' *ZXY_etc_passwd* i have tried this for i... (2 Replies)
Discussion started by: pinnacle
2 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question