Hi All
Please help me to remove the first 2 character from the file name.
files are like this
$ ls
12aman file
13atul si
56rana se
I want to remove the first 2 char which are numbers.
I want the o/p like thus
aman file
atul si
rana se
thanks for help
oky
2
sed -i 's/^..//g' filename
Please note this will modify the source file with the required output.
if the -i option doesn't supported please redirect the output to a file.
awk ' { print substr($0,3,length($0)) }' filename > new_file_name
thanks guys..
But I want to change the name of files which have space in between.
like this
mv '12papa doc' 'papa doc'
this is simple for one file, but I want to write a code which can able to change many files.
I tried this
for foobar in * ;
do
temp=`echo "$foobar" | cut -c 3-`
mv $foobar "$temp" ;
done
and got this error
$ ls
aman singh
papa mummy
Error
mv: target `an singh' is not a directory
mv: target `pa mummy' is not a directory
please help
Rksiva
6
Check this, it will remove all the leading numbers,
sed 's/^[0-9]*//g' inpfile
Quote variable foobar as well in the mv command and try
mv "$foobar" "$temp"
thanks Man
I miss the quotes
thanks a lot
panyam
9
A final script will be something like this:
ls [0-9][0-9]* | while read line
do
new_f=`echo "$line" | sed 's/..//'`
mv "$line" "$new_f"
done