Part of string with script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Part of string with script
# 1  
Old 06-25-2012
Part of string with script

Hi All,
I have few files named.
abcd.docx
abcde.doc
abcdef.temp
I wish if I could extract the string upto .(dot),and not the extension.
Thanks a lot.
Kind regards,
Indranil.
# 2  
Old 06-25-2012
bash

Hi,

Try this one,
Code:
cd dir
for i in *
do
   filebase=${i%.*%}
   echo ${filebase}
done

Cheers,
Ranga:-)
# 3  
Old 06-25-2012
thanks.....but i have many files in many sub directories and I want to move all of them to .txt extension.....single line command would be handy......any idea....
thanks for replying.
# 4  
Old 06-25-2012
Hi, you may try this...
Code:
for i in `find . -type f `; do dirbase=`dirname ${i}`; fylbase=`basename ${i}`; fylname=${fylbase%.*}; mv ${i} ${dirbase}/${fylname}.txt; done


Last edited by Franklin52; 06-25-2012 at 03:18 AM.. Reason: Please use code tags for data and code samples
# 5  
Old 06-25-2012
Try this .. (include the highlighted part if the below command provides expected output)
Code:
$ find dir_location -type f | awk -F\. '{print "mv "$0" "$1".txt"}' | sh


Last edited by jayan_jay; 06-25-2012 at 03:48 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace part of string?

Hi Gurus, I need to replace part of string in file, the string format is below: I can use ABCD to find string, then replace values after "=" sign ABCD_XXX=value ABCD_YYY=value after replace ABCD_XXX=new_value ABCD_YYY=new_value my OS is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ... (9 Replies)
Discussion started by: green_k
9 Replies

2. UNIX for Dummies Questions & Answers

Intersection by part of the string

Hi, I like to intersect two files based on their first columns. Here is the code which does the trick for me: awk 'NR==FNR{A;next}$1 in A' file1 file2 However, this only looks for exact matches between the two files in the first column. I need them to be printed even if part of the string... (10 Replies)
Discussion started by: a_bahreini
10 Replies

3. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

4. Shell Programming and Scripting

Editing part of the string

Hi guys got a problem here hope u all can help me. I learn that sed can actually edit a string but you need to know the old attribute to change to new 1. Example: sed "s/$title:$author/$title:$Nauthor/g" "Harry Potter - The Half Blood Prince:J.K Rowling:40.30:10:50" Each delimiter : represent... (4 Replies)
Discussion started by: GQiang
4 Replies

5. Shell Programming and Scripting

Need to take one part from a string

I have a string something like "/opt/src/default.cfg" OR /opt/src/common/one This whole string stored in an array. The problem is this string is not constant and it will keep on changing as lot of strings are stored in the array and it will be look like :- case 1 /opt/src/default.cfg ... (8 Replies)
Discussion started by: Renjesh
8 Replies

6. Shell Programming and Scripting

Part of a string

Hi mates, I am doing a script in ksh. I have the following string: /opt/one/two/four/five/myFile.txt And I have a variable: echo "${variable}" -> /opt/one/two/ I would like to have just the string: four/five/myFile.txt What is the better way to do that? Thanks in... (3 Replies)
Discussion started by: gonzaloron
3 Replies

7. Shell Programming and Scripting

Delete part of string

This command: du -s /Applications/TextMate.app Returns an output like this: 65792 /Applications/TextMate.app I need to delete the space and the file path in the output leaving just the number. Thanks (2 Replies)
Discussion started by: pcwiz
2 Replies

8. Shell Programming and Scripting

Getting part of a string

Hi, I have a string assinged to a varaible as below. FILE=/var/adm/message If $FILE is the value where it stores the path of message file. I would like to extract the location of the file message as below LOCATION=/var/adm FILE may have value like /var/adm/xxxx/message ... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

9. UNIX for Dummies Questions & Answers

regarding replace a part of a string

hi all. i have a file name like abcd_vbnh.a_p i have to copy it as abcd_vbnh.a every time... in unix not in perl please (7 Replies)
Discussion started by: madhu_aqua14
7 Replies

10. Shell Programming and Scripting

how to get the last part of a string followed by a pattern

assuming "cat" is the pattern, string (regardless length) asdadfcat4 I need to get 4 for eirtrjkkkcat678- I'd get 678 (in b-shell) Thanks in advance!!! (4 Replies)
Discussion started by: bluemoon1
4 Replies
Login or Register to Ask a Question