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
gary_w
3
$ cat efs
#!/bin/ksh
file1="test_junk_file__20120210092009.txt"
print "${file1%__*}.${file1#*.}"
exit 0
$ efs
test_junk_file.txt
$
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 '.'`
gary_w
6
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 '.'`
gary_w
8
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.