Want to make folder named as last three characters of a file name (length of file name can vary file to file)
E.g File name is AAAACCCCBBBB.txt (12 Characters excluding file extension) then folder to be created is BBB
Irrespective of length of file name, script should use only last 3 characters (Excluding file extension) to make folder.
What can i do to grep 50th line of each txt file in a directory?
if you have Python and can use it, here's an alternative
import os
DIR="/home/path"
for files in os.listdir(DIR):
if os.path.isfile(files) and files.startswith("AAAA"):
folderToBeCreated = files.split(".")[:-1][-1][-3:]
folderToBeCreated = os.path.join(DIR,folderToBeCreated )
if not os.path.exists( folderToBeCreated ):
os.mkdir(folderToBeCreated)
import os
DIR="/home/path"
for files in os.listdir(DIR):
if os.path.isfile(files) and files.startswith("AAAA"):
for n,lines in enumerate(open(files)):
if n==49:
print lines.strip() #print 50th line
break
Dear frnds,
I have tried solution given by Fedora (sed 's/^.*\(...\)\..*/\1/'), but its not working (Nothing is happening).. please tell me if there is some alternate solution?
Thanx for your reply. Its working fine. I have a request. Can some one please please explain me this command briefly?
I got it till echo 'AAAACCCCBBBB.txt' | sed 's/^.\(...\)
but didnt get remaining part i.e \../\1/'