I have a text file which has 1000 rows/entries. These 1000 entries correspond to the column names for my dataframe. These are the new features that need to be added to the dataframe for model development. My input text file looks like this:
show temperature all#Total Numbers Approved#g2/3
show temperature all#Total Numbers Approved#g2/2
show temperature all#Total Numbers Approved#g2/4
show temperature all#Total Numbers Approved#g0/2
show temperature all#Total Numbers Sent#g1/2
show temperature all#Total Numbers Sent#g1/3
show temperature all#Total Numbers Sent#g1/1
formulastat gpucores all parameter function-frames#formula:1#gpucores:11
formulastat gpucores all parameter function-frames#formula:1#gpucores:10
formulastat gpucores all parameter function-frames#formula:2#gpucores:10
formulastat gpucores all parameter function-frames#formula:2#gpucores:11
formulastat gpucores all parameter function-frames#formula:0#gpucores:8
I was looking to automatically add '' for each line, remove the line break and add a comma after each line entry. Expected output is as follows:
'show temperature all#Total Numbers Approved#g2/3', 'show temperature all#Total Numbers Approved#g2/2', 'show temperature all#Total Numbers Approved#g2/4', 'show temperature all#Total Numbers Approved#g0/2', 'show temperature all#Total Numbers Sent#g1/2', 'show temperature all#Total Numbers Sent#g1/3', 'show temperature all#Total Numbers Sent#g1/1', 'formulastat gpucores all parameter function-frames#formula:1#gpucores:11', 'formulastat gpucores all parameter function-frames#formula:1#gpucores:10', 'formulastat gpucores all parameter function-frames#formula:2#gpucores:10', 'formulastat gpucores all parameter function-frames#formula:2#gpucores:11', 'formulastat gpucores all parameter function-frames#formula:0#gpucores:8'
\x27
apply to perl and/or sed? – Ed Morton Sep 20 '20 at 18:03GNU sed
(and possibly many other implementations):\xxx Produces or matches a character whose hexadecimal ASCII value is xx.
(it is restricted to two digits)... for perl, it requires\x{}
form if you need more than two hex characters.. so, as far as I know,\x27
is robust for both sed/perl... and for GNU awk -As of version 4.2, only two digits are processed.
– Sundeep Sep 21 '20 at 02:57\047
with perl and it worked too but with sed - not so much! – Ed Morton Sep 21 '20 at 03:02\047
in sed will be treated as\0
(alias for&
) followed by47
.. you'll need\oNNN
for octal and\dNNN
for decimal formats – Sundeep Sep 21 '20 at 04:21