bash - Single-quote part of a line using sed or awk -


convert input text follows, using sed or awk:

input file:

       113259740 qa test in progress        219919630 uat test in progress 

expected output:

       113259740 'qa test in progress'        219919630 'uat test in progress' 

you try gnu sed command also,

sed -r "s/^( +) ([0-9]+) (.*)$/\1 \2 '\3'/g" file 
  • ^( +), catches 1 or more spaces @ starting , stored in group(1).

  • ([0-9]+) - after catching 1 or more spaces @ starting, next matches space after , fetch numbers next space store in group(2).

  • (.*)$ - fetch characters next numbers upto last character , store in group(3).

  • all fetched groups rearranged in replacement part according desired output.

example:

$ cat ccc        113259740 qa test in progress        219919630 uat test in progress  $ sed -r "s/^( +) ([0-9]+) (.*)$/\1 \2 '\3'/g" ccc        113259740 'qa test in progress'        219919630 'uat test in progress' 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -