Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
From the line
/mnt/sampleserver/test_1/myfile.pdf
in my text file I want to remove
/mnt/sampleserver/test_1/
Please suggest me how to do it using linux commands.
basename
Use the 'basename' command. Something like this: basename /mnt/sampleserver/test_1/myfile.pdf
basename /mnt/sampleserver/test_1/myfile.pdf
Add a comment
myfile.pdf
Several ways:
file="/mnt/sampleserver/test_1/myfile.pdf" $ echo ${file##*/} myfile.pdf $ echo $file | cut -d/ -f5 myfile.pdf $ echo $file | awk -F/ '{print $5}' myfile.pdf
You can use any text processing tool, for example, sed:
% echo "/mnt/sampleserver/test_1/myfile.pdf" | sed -e 's|/mnt/sampleserver/test_1/||' myfile.pdf
Following should get you going. (Note the "\" for escape character)
/bin/sed -i "s//mnt/sampleserver/test_1///"
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
basename