need to Delete first 10 characters of a file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to Delete first 10 characters of a file name
# 1  
Old 02-01-2011
need to Delete first 10 characters of a file name

Hello Everyone,

I need help in deleting first 10 characters from the filename in a directory

eg:
1234567890samplefile1.txt
1234567890samplefile2.txt
and so on..

need to get the output as
samplefile1.txt

Thanks in Advance!!!!
# 2  
Old 02-01-2011
try:

Code:
for i in `ls *sample*.txt|sed 's/[0-9]*s/s/'`
do
cp *$i $i
done

# 3  
Old 02-01-2011
Hi Olivia,
If it is always first 10 characters to be ignore while printing, below command may help you. List them first and using "cut" command print them from 11th character till end of file name.

ls -1|cut -c 11-

If this is not working, you can have requirement explained more clear.

Cheers,
Chanakya
This User Gave Thanks to Chanakya.m For This Post:
# 4  
Old 02-01-2011
Code:
file=1234567890samplefile1.txt

mv $file ${file:10}

# 5  
Old 02-01-2011
Quote:
Originally Posted by yinyuemi
try:

Code:
for i in `ls *sample*.txt|sed 's/[0-9]*s/s/'`
do
cp *$i $i
done

Thanks for your reply but am getting an error as cp 1234567890samplefile1.txt and 1234567890samplefile1.txt are identical

Can you please help me out!!
# 6  
Old 02-01-2011
Quote:
Originally Posted by yinyuemi
try:

Code:
for i in `ls *sample*.txt|sed 's/[0-9]*s/s/'`
do
cp *$i $i
done

breaks on files with white spaces. don't use ls with for loop like that. Use the shell.
Code:
for file in *sample*.txt 
do
  
done

# 7  
Old 02-01-2011
Code:
$ echo 1234567890samplefile1.txt | ruby -e 'print gets[10..-1]' 
samplefile1.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to delete special characters exists only at the end of the each record in UNIX file?

Hi, I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following: Sed -e 's/ /g;s/ */ /g' . But It is removing special characters exists everywhere in the file(begining,middle... (24 Replies)
Discussion started by: rakeshp
24 Replies

2. Shell Programming and Scripting

how to delete special characters from the file content

Hello Team, Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content. ---------------------------------------- Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
Discussion started by: kanakaraju
2 Replies

3. UNIX for Dummies Questions & Answers

Vim help - delete words in a file or characters after pattern

I have a file with words that begin with character #. Whenver that character is found that word should be deleted throughout the file. How do I do that in VIM. e.g: afkajfa ladfa ljafa #222222 kjafad ljl afajkj kjlj uouu #44444 jlkj lkjl Output should be afkajfa ladfa ljafa kjafad... (1 Reply)
Discussion started by: osbourneric
1 Replies

4. Shell Programming and Scripting

Delete new line characters from a file

Hi, I have a file with about 25 colums separated with '~', but few of the lines have extra tabs ('^') and new line characters ('$'). Is there a way I can delete those characters if they are anywhere before the 25th column in a line? example: CLUB000650;12345678;0087788667;NOOP MEMBER ... (4 Replies)
Discussion started by: rudoraj
4 Replies

5. Shell Programming and Scripting

How to delete characters using a file

Hi All, I have a configuration file (file.cfg) in which data will be like this ; , _ + a to z A to Z Now i have to read a textfile (file.txt) and i need to check whether there is any other character present in text file that is not existing in (file.cfg). If other characters are present... (4 Replies)
Discussion started by: krishna_gnv
4 Replies

6. Shell Programming and Scripting

Delete not readable characters

Hi All, I wanted to delete all the unwanted characters in the string. ie, to delete all the characters which are not alpha numeric values. var1="a./bc" var2='abc/\."123' like to get the output as print var1 abc print var2 abc123 Could you guys help me out pls. Your help is... (3 Replies)
Discussion started by: ajilesh
3 Replies

7. UNIX for Dummies Questions & Answers

how to delete M-^M characters from a file

I am receiving a file with 'M-^M' characters...how do I get rid of these characters. I tried tr -d '\015' and sed '/^M//g', but they didnot work. Appreciate if someone can help me with this (1 Reply)
Discussion started by: hyennah
1 Replies

8. UNIX for Dummies Questions & Answers

delete non printable characters from file

i have a file which contains non printable characters like enter,escape etc i want to delete them from the file (2 Replies)
Discussion started by: alokjyotibal
2 Replies

9. UNIX for Dummies Questions & Answers

How to delete a file with special characters

I don't now exactly how I did it, but I created a file named " -C " cexdi:/home1 $ls -lt total 1801336 -rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C How do I delete this file ? cexdi:/home1 $rm -C rm: invalid option -- C Syntax : rm filename ... Doesn't work...... (5 Replies)
Discussion started by: yveslagace
5 Replies

10. Programming

how to insert and delete characters in the middle of file

I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
Login or Register to Ask a Question