juicebyah
juicebyah

Reputation: 141

remove first text with shell script

Please someone help me with this bash script, lets say I have lots of files with url like below:

https://example.com/x/c-ark4TxjU8/mybook.zip
https://example.com/x/y9kZvVp1k_Q/myfilename.zip

My question is, how to remove all other text and leave only the file name?

I've tried to use the command described in this url How to delete first two lines and last four lines from a text file with bash?

But since the text is random which means it doesn't have exact numbers the code is not working.

Upvotes: 0

Views: 147

Answers (2)

MLSC
MLSC

Reputation: 5972

You can use awk:

The easiest way that I find:

awk -F/ '{print $NF}' file.txt

or

awk -F/ '{print $6}' file.txt

You can also use sed:

sed 's;.*/;;' file.txt

You can use cut:

cut -d'/' -f6 file.txt

Upvotes: 1

Yaitzme
Yaitzme

Reputation: 241

You can use the sed utility to parse out just the filenames

sed 's_.*\/__'

Upvotes: 2

Related Questions