Split on last occurance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split on last occurance
# 1  
Old 09-07-2008
Split on last occurance

I want to call a script like this:

Code:
./somescript some-thing[who].knows.what.ending

Inside the script it needs to split at last .(period)
so I can:
Code:
a=some-thing[who].knows.what
b=ending

I know I can do it in perl but im still learing awk and sed.

Thanks
# 2  
Old 09-07-2008
Use parameter expansion.
Code:
a=${1%.*}
b=${1##*.}

Do you really want to use awk or sed?
# 3  
Old 09-07-2008
Quote:
Originally Posted by danmero
Use parameter expansion.
Code:
a=${1%.*}
b=${1##*.}

Do you really want to use awk or sed?
Not if I dont have too...

Is there a cheat sheet somewhere for these?

Works great thanks... Smilie
# 4  
Old 09-07-2008
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract only first occurance

Hi All, From the below file. I need to get only the first occurrence and print. I tried to do it in separate grep not coming as expected Original file 11001;1213;304;;;;;;;111020677.64;;;;;;;;;;;;;;;;;;;;;;;;;; 11001;1214;304;;;;;;;102376462.96;;;;;;;;;;;;;;;;;;;;;;;;;;... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

2. Shell Programming and Scripting

Multiple occurance of file

Hi all, I have file structure as file.log 84t-rw-r--r-- 1 emily04 us_cms 24492717 Oct 5 13:29 vgtree_84_1_K3L.root 85t-rw-r--r-- 1 emily04 us_cms 50410380 Oct 5 16:06 vgtree_85_1_uZv.root 85t-rw-r--r-- 1 emily04 us_cms 50567380 Oct 5 16:06 vgtree_85_1_hjv.root 86t-rw-r--r-- 1 emily04... (4 Replies)
Discussion started by: emily
4 Replies

3. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

4. Shell Programming and Scripting

Trying to grep for '--' occurance

Hello Im trying to grep for a string in grub.conf . I've used the -F option since its a long string, but when i execute, i run into errors. Script and output below. GRUBPASSWD="password --md5 xyz" if grep -Fxq $GRUBPASSWD /etc/grub.conf then . . output: grep: unrecognized option... (5 Replies)
Discussion started by: bludhemn
5 Replies

5. Shell Programming and Scripting

First occurance

A PERL script that prints just the first occurrence of a string in a file and immediately exits (the string and the filename are the first and the second command line arguments; I used filehandle to open an input file). (1 Reply)
Discussion started by: aadi_uni
1 Replies

6. UNIX for Dummies Questions & Answers

Replace first 5 occurance of a pattern

There is scenario that i have to replace a pattern at the first 5 occurance in a file. say i need to replace 'abc' by 'xyz' at its first 5 occurance in a file a.txt, can anybody help me how it can be done, i can do complete replacement of the pattern using sed throughtout the file. (1 Reply)
Discussion started by: palash2k
1 Replies

7. Shell Programming and Scripting

How to insert values in 1st occurance out of two occurance in a file

Hi I have a file which contains the following two lines which are same But I would like to insert the value=8.8.8.8 in the 1st occurance line and value=9.9.9.9 in the 2nd occurance line. <parameter name="TestIp1" value=""> <parameter name="TestIp1" value=""> Please suggest (1 Reply)
Discussion started by: madhusmita
1 Replies

8. UNIX for Dummies Questions & Answers

replace the n'th occurance in a file

Hi All, How can i replace the n'th occurance in a file. ? I have a property file like EAR;_TrackingEAR;META-INF/application.xml;xml;context-root;1;valeur EAR;_TrackingEAR;META-INF/application.xml;xml;context-root;2;valeur2... (2 Replies)
Discussion started by: subin_bala
2 Replies

9. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

10. Shell Programming and Scripting

awk: last occurance

Hi All, I need to extract the last occurance of a pattern match. So far I've got the code below which extracts the first occurance. Any ideas how I can modify it so that it extracts the last? BEGIN {} { if (data++ == 0) ... (17 Replies)
Discussion started by: pondlife
17 Replies
Login or Register to Ask a Question