Substring with specific condition
hi ,
I am trying to substring a line which is got while reading property file using shell scripting. The line is something like this: file\:/aaa/ccc/dd.jar, \^M I am trying to get the substring as /aaa/ccc/dd.jar Tried using awk for the same but not getting the right command. Thanks |
Assuming you want the string between : and , then:
Code:
awk -F '(:)|(,)' '{ print $2 }' input.txt |
Doesn't have to be quite so flash :)
Code:
awk -F"[:,]" '{print $2}' file |
Quote:
A point of style, though -- I would use single quotes for bash wherever double quotes are not necessary. |
Hey thanks for your replies!!
Just for anyones interest ,I tried another way of doing it : cut -d: -f2 | cut -d, -f1 |
If you can get the string into a bash variable, there are quite a few options available.
Use parameter substitution: Code:
string='file\:/aaa/ccc/dd.jar, \^M' Code:
string='file\:/aaa/ccc/dd.jar, \^M' Code:
string='file\:/aaa/ccc/dd.jar, \^M' Code:
string='file\:/aaa/ccc/dd.jar, \^M' Quote:
|
All times are GMT -5. The time now is 06:48 PM. |