2017
01
05

先頭ではなく後方の文字列を取得したいときのbashスクリプト

よく使うので、自分用のメモ。
たとえば、

hxxp://example.com/abc.exe
hxxp://test.com/efg.png

上記URLからファイル名のみを取得したい場合。

$ echo -e "hxxp://example.com/abc.exe\nhxxp://test.com/efg.png" | rev | cut -c 1-7 | rev
abc.exe
efg.png

revで文字列をすべて反転させてcutでn番までの文字を抽出、もう一度revで反転させた文字列を元に戻します。

以上。

2017年3月31日追記
basenameコマンドの存在を知る
$ basename "hxxp://example.com/abc.exe"
abc.exe
$ basename "hxxp://test.com/efg.png"
efg.png
Comment



Only the blog author may view the comment.

[13]

I'm extremely impressed with your writing skills and
also with the layout on your blog. Is this a paid theme
or did you modify it yourself? Either way keep up the nice
quality writing, it is rare to see a nice blog like this one nowadays.

[22]

This is the right webpage for everyone who really wants to understand this topic.
You know a whole lot its almost tough to argue with you (not
that I personally will need to?HaHa). You definitely put a fresh spin on a subject that has been written about for many years.
Excellent stuff, just wonderful!

[45]

I am very happy to read this. This is the kind of manual that needs to be given and not the random misinformation that is at the other blogs.

Appreciate your sharing this best doc.

Trackback
Trackback URL

«  | HOME |  »

奇妙な風景 Unique Scene
<< >>

プロフィール


最新記事


最新コメント


最新トラックバック


月別アーカイブ


カテゴリ


スポンサード リンク


FC2カウンター


検索フォーム


RSSリンクの表示


リンク


ブロとも申請フォーム


QRコード