Need help in reading a filename

Hi Guys,

I have the following input.

test_junk_file__20120210092009.txt
latest_file__20120210092009.txt
side_load_junk_file__20120210092009.txt

I need to exclude the timestamp part from the file.

so, the output should be as follows.

test_junk_file.txt
latest_file.txt
side_load_junk_file.txt

Could you please help me out here..

Cheers!!!!!!

With Sed..

sed 's/__[0-9]*//' inputfile
$ cat efs
#!/bin/ksh

file1="test_junk_file__20120210092009.txt"

print "${file1%__*}.${file1#*.}"

exit 0
$ efs
test_junk_file.txt
$

Yeah Guys,,

That Worked perfectly :slight_smile:

oldname=ytyytu_uyhsudh_1218788_1212__212121212.txt

newname=`echo $oldname|awk -F'__' '{print $1}'`.`echo $oldname|cut -f2 -d '.'`

---------- Post updated at 06:54 AM ---------- Previous update was at 06:53 AM ----------

oldname=ytyytu_uyhsudh_1218788_1212__212121212.txt

newname=`echo $oldname|awk -F'__' '{print $1}'`.`echo $oldname|cut -f2 -d '.'`

P.S. Here's a resource that includes string operations if your shell supports them:
Reference Cards

on top of elixir

newname=`echo $oldname|awk -F'_[0-9]' '{print $1}'`.`echo $oldname|cut -f2 -d '.'`

Why do all that piping and command substitution which all use resources when built-in string operations will do it?

I guess if you are forced to use a shell that does not support string operations.