input string

prashant@prashant:~/Desktop$ xyz /123/ {print } abc.txt

after using awk command to strip on above input string I should get below

output string

xyz /123/ {print } abc.txt


awk -F'$' '{print $2}' <<<"$str"

or if you don't want a space from the beginning try:

awk -F'xyz' '{print FS $2}' <<<"$str"

where the input string is stored in str variable as following:

str="prashant@prashant:~/Desktop$ xyz /123/ {print } abc.txt"


  • The -F'$' defines the Field Separator to $
  • The print $2 prints the second filed $2 with $ as field separator between them.
  • The FS in second command will prints the entry of Field Separator which is defined to xyz.
  • Also I want to know getting the required output using regular expression substitution.ie using like awk '{sub(/prashant/\@prashant/\:\~/\/Desktop\/$/,"");print}' abc.txt. I am using this command but getting regular expression error – prashantb j Jan 7 '15 at 13:33
  • @prashantbj Glad it worked. For that try awk '{sub(/prashant\@prashant\:\~\/Desktop\$ /,"");print}' <<<"$str" and don't forget please mark the answer as accepted. thanks – αғsнιη Jan 7 '15 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.