Display last 8 character of filename

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display last 8 character of filename
# 1  
Old 10-30-2009
Display last 8 character of filename

I would like to display the last 8 characters of the filenames for filenames of different lengths.

I can delete the last 8 characters with sed but dont know how to only show the last 8 characters.

The filenames are something like;


I have used;

echo $file | sed -e 's/........$//g'

Any help is greatly apprecaited.


# 2  
Old 10-30-2009
You can use something like this:

tot=`echo $texto | wc -c`
echo $texto | cut -c `expr ${tot} - 8`-

Last edited by pogdorica; 10-30-2009 at 10:57 AM..
# 3  
Old 10-30-2009
$ echo "afxH340800340000" | sed -e 's/.*\(.\{8\}\)$/\1/'

# 4  
Old 10-30-2009
Originally Posted by pludi
$ echo "afxH340800340000" | sed -e 's/.*\(.\{8\}\)$/\1/'

Thanks so much, this worked excellent!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

^M special character in Filename

Hi All, Special character ? is added in between filename. Am not able to figure our why this is happening. In my Development environment special characters are not present. This issue is happening in the higher environment. It would be helpful if somebody can tell what are the possible... (3 Replies)
Discussion started by: weknowd
3 Replies

2. Shell Programming and Scripting

UNIX script to display the filename

Hi All How to answer the below interview question.. With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename (2 Replies)
Discussion started by: shumail
2 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. Shell Programming and Scripting

Display the Filename and Size of a File

Hello, all! Working in a Bourne shell. What command would list the filename and size of a file if the size of the file had to be bigger than $a and smaller than $b? Output (if $a is 10 bytes and $b is 50 bytes):test1.txt 15 test2.txt 30 test3.txt 50 Thanks, Ann :p (3 Replies)
Discussion started by: LowlyIntern
3 Replies

5. Shell Programming and Scripting

Remove last character from filename

Hi All, I have different type of file (.txt,.csv,.xml) format in my current directory. My requirement is that I need to remove the last character from the file format. Example count.txt$ csp_rules.csv^ Date.xml~ Need Output: count.txt csp_rules.csv Date.xml How to do that?.... (5 Replies)
Discussion started by: suresh01_apk
5 Replies

6. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

7. UNIX for Dummies Questions & Answers

how to display date with filename??

Hi i am currently using below command in shell script and calling it from cron job. This is to take daily backup with the date as suffix to the file.When i try i unable to get the date suffixed to the backup file. Please help me as to wt's wrong in this or how to get the date added to the... (5 Replies)
Discussion started by: abhi_n123
5 Replies

8. Shell Programming and Scripting

display filename with date

Hi buddies, I have a doubt. I want to display filename with date in the following format.Is there any way to do this. Kindly give me the solution. I want to display the result in the following manner. test1.txt 03/28/2008 testlog.log 02/20/2008 Please let me know one solution how to do... (1 Reply)
Discussion started by: pstanand
1 Replies

9. Shell Programming and Scripting

Filename character changes

I want to make a script for change filename's character not in English for a given directory. But I am not sure where am I starting from due to I am a little bit new user for scripts. At least is there anybody can help me to make first step ,how can I find illegal or unwanted characters in file... (5 Replies)
Discussion started by: xramm
5 Replies

10. UNIX for Dummies Questions & Answers

Display filename and wc stats

I'm just learning UNIX and I'm trying to do the following: Write a script called details.bash that, for each file in the working directory, prints the filename, the # of lines, and the # of words to to some output file, like this: filename1 73 431 filename2 5 21 It's probably a stupid... (1 Reply)
Discussion started by: asianmike
1 Replies
Login or Register to Ask a Question