Regular expression – What is the best way to make a string operation in a shell script?

I have a path as a string in a shell script, which can be absolute or relative:

/usr/userName/config.cfg< /p>

or

../config.cfg

I want to extract the file name (the part after the last one, so in this case: “config. cfg”)

I think the best way is to use some simple regular expressions?
Is it correct? Should I or should I use sed or awk?

The string manipulation function of the Shell script itself looks very original and very esoteric.

Any sample solutions are also appreciated.

I just use instead of string manipulation

file=` basename "$filename"`

Edit:

Thanks for relaxing some new syntax (assuming your file name is saved in $filename):

file=$(basename $filename)

I have a path as a string in a shell script, which can be absolute or relative:

/usr/userName/config.cfg

or

../config.cfg

I want to extract the file name ( After the last one, so in this case: “config.cfg”)

I think the best way is to use some simple regular expressions?
Is it correct? Should I or should I use sed or awk?

The string manipulation function of the Shell script itself looks very original and very esoteric.

Any sample solutions are also appreciated.

I just use instead of string manipulation

file=`basename "$filename"`

Edit:

Thanks for relaxing some new syntax (assuming your file name is saved in $filename):

file=$(basename $filename )

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5433 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.