awk remove non-numerical values -


I just need to keep 'line' which starts with 'now'; And there is no letter between 'now' and 'cd'. I need to remove 'AB' and 'CD' from these lines.

Input:

  abi am jhoncd ab32.58cd abi live in AB 22 of America. My birth was in NYCD ab58.2cd ef  

output:

  32.58 58.2  

thanx people!

via awk,

  $ awk '/ ^ ab [^ Az] + cd $ / {gsub (/ now /, ""); Gsub (/ cd /, ""); Print} 'file  

OR

  $ awk' / ^ ab [^ [alpha:]] + cd $ / {gsub (/ ab / , ""); Gsub (/ cd /, ""); Print} 'file 32.58 58.2  

searches for the above awk command lines which starts with ab followed by alphabet (or alphabetical) characters It does not happen again or after it, if it gets any earlier on the string cd , then it will be able to enter the string ab gsub Code> and cd . Finally the result was redirected to standard output.

Pattern Details:

  • ^ It indicates that we start the line.
  • matches ab string ab
  • [^ az] + Az matches any character of one or more times.
  • matches the cd string cd
  • $ the end of the line.

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -