Quantcast
Channel: d0wn
Viewing all articles
Browse latest Browse all 75

BASH : Delete the last X chars from a string

$
0
0

When you scrap data in HTML , it’s common , depending on the quality of you regex to end up with a string with some useless character at the end (Or the Beginning),

If you string looks like that :

My useful data</a> <

You can use the command head to drop the X last character of your string ,
So in my Case , to Keep only the string My useful data and drop the </a> <

I’m going to pipe my string to

head -c -6

This will delete the last 6 chars of my string , giving the data that i need later in my script

 

 


Viewing all articles
Browse latest Browse all 75

Latest Images

Trending Articles