Set the last 4 letter in the filename as a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set the last 4 letter in the filename as a variable
# 1  
Old 04-28-2010
Set the last 4 letter in the filename as a variable

Hi all,

I want to set the last 4 letter in the filename as a variable.
For example, i have AB1234.txt file and i need to have last 4 letter as a variable.

It should be like ;

get last four letter
set var = 1234

How can i write this in C shell??

Thanks,
zibi
# 2  
Old 04-28-2010
Clarify what you are asking with some example. In any case, you should drop csh to something more suitable for scripting like ksh or bash.
# 3  
Old 04-28-2010
Hi Jlliagre, i try to clarify more things but my case like the following;

There is a file named
ABC1234.txt

Script should get the last 4 letter in filename, that would be (1234).
This value will be my variable for further process.

I dont know the CSH codes for these process, that's why i could not write any code.

Thanks,
zibi
# 4  
Old 04-28-2010
MySQL

Can sed usage be?

Code:
set a="alasisas2323423dsdwe112313ll';lthelast1234.txtasa1218jkhjkh12121"

Code:
[root@sistem1lnx ~]# echo $a | sed 's/.*\(....\)\.[a-zA-Z]*[0-9]*.*/\1/'
1234

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting letter as variable

I need to pass letter like "c" for "-copy" and need to read by variable $sel_mod, My I know the good way of writing the script. Example: Select one of the Clone Mode ( '-copy', '-differential', '-precopy', '-nopcopy') Type the Clone mode : c Thanks in advance, Ashan ... (6 Replies)
Discussion started by: ashanabey
6 Replies

2. Shell Programming and Scripting

Get letter from number and assign to a variable

Hi to all in forum, I'm trying to convert the letter number between 1 (A) and 26 (Z), that part is working, my issue is how to assign the printf output to a variable:LetterNumber=10 printf "\x$(printf %x $((${LetterNumber}+64)))" $ J #The problem, how to assign printf output (J in this... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

3. Shell Programming and Scripting

Trying to take a string and break each letter into a separate variable

I am trying to make a script that takes a word and each letter up and turns it into a separate variable. My code currently does not work but I feel I just need to tweak one thing that I am unsure of. (ex: if forum was typed in letter1=f; letter2=o; letter3=r;...) Thank you count=1; ... (7 Replies)
Discussion started by: crimputt
7 Replies

4. Shell Programming and Scripting

Extract date from filename and set timestamp

I have lots of files in this format: dvgrab-2003.06.29_15-30-24.mpg The numbers represents the date and time (YYYY.MM.DD_HH-MM-SS) How can I extract the dates from the filenames, and use the dates in the file timestamp? I guess this can be done by using "find", "sed" and "touch"? Can... (6 Replies)
Discussion started by: qwerty1234
6 Replies

5. Shell Programming and Scripting

HOWTO - change letter case of variable value

Hi I have e.g. VAR1=january and I need to change it into VAR1=January. How to change value of VAR1 variable to always set first character uppercase and other lowercase ? thx for help. (9 Replies)
Discussion started by: presul
9 Replies

6. Shell Programming and Scripting

Trying to capitalize first letter of every word in Variable

Total Bash noob, have been successful in doing my script by searching and looking at examples, but I need some assitance with this one, just can't figure it out. In the Bash script I am trying to capitalize the first letter of every word in a string, ideally not changing other capitalization. ... (5 Replies)
Discussion started by: randyharris
5 Replies

7. Shell Programming and Scripting

how does set--$(ls -l filename) work?

i'm not too sure how to use set--$(ls -l filename) to set values of positional parameters. i'm supposed to write a script that accepts a directory as an optional command line parameter. and for that directory, i'm supposed to display a single line of information about each file within it: file... (3 Replies)
Discussion started by: jaay
3 Replies

8. Shell Programming and Scripting

AWK set FILENAME via user input

I am trying to write a awk script that prompts user for input to set the FILENAME varable. I can get it set, but I think awk is not doing anything with it. this is what I have so far #!/usr/bin/nawk -f BEGIN { FILENAME = "" printf "Enter name of file to check in : " ... (2 Replies)
Discussion started by: timj123
2 Replies

9. Shell Programming and Scripting

using sed to add letter after variable

Hi All, I need to have a sed command insert the letter i at the end of some lines in a file. Problem is that where I want to add the i is after variables that change in each file eg, tsal314384' tsal315386' tsal317392' I need to have it like this ... (2 Replies)
Discussion started by: outthere_3
2 Replies

10. UNIX for Advanced & Expert Users

how to read each letter from file and store it in variable.

Dear friends, i am writing csh script i have one dat file containing following data.like this. 08FD3 03A26 000FA0 FFFF0 BBA0F 00000 00000 from the above file i want to read each letter and store it in one variable. how it is possible. please help (7 Replies)
Discussion started by: rajan_ka1
7 Replies
Login or Register to Ask a Question