Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cutting some part of file name 2

Status
Not open for further replies.

longs

Programmer
Jul 27, 2007
31
US
HI All

I would like to cut a part of the file name

I have a flat file lets say ABC12345.TXT and 2nd file name is DELL500.TXT

file_name=$(echo ABC12345.TXT | sed/\.TXT//)
file2=DELL500.TXT

I would like to create a new name by joining some parts of both the names;
I want the out put to be ABC12345L500.log
So far I am able to join both the names like
ABC12345DELL500.TXT.log by using the folloing;

new_name=$file_name$file2.log

How can I cut some part from a the file name. I tried to use cut using -c option but its cutting the contents of the file.

Thanks

 
This was able to help me

s=`echo $file2 | cut -c 4-7`
print $file2$s.log

 
Maybe this...
Code:
FILE1=ABC12345.TXT
FILE2=DELL500.TXT

NEWNAME=`basename ${FILE1} .TXT``basename ${FILE2} .TXT`.log
The command [tt]basename[/tt] is a good way to chop off the extension and any path, assuming to know what the extension is. "[tt]man basename[/tt]" for more info.
 
Also, if you're in Korn Shell, maybe this...
Code:
FILE1=ABC12345.TXT
FILE2=DELL500.TXT

NEWNAME=${FILE1%.TXT}${FILE2%.TXT}.log

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top