nimo
1
Hi everyone
I have file1 contains:
'7832'
' 8765
6543
I want a sed command that will format as:
'7832' , '8765' , '6543'
I tried
sed -e s/\'//g -e 's/^[ ^t]*//;s/[ ^]*$//' file1 > file2
sed -e :a -e '$!N; s/\n/ /; ta' file2
which gives: 7832 8765 6543
I need some help to continue with this. Thanks
awk -vORS=" , " '{gsub("[^0-9]","");print"#"$0"#"}' file1 | tr "#" "'"
nimo
3
Thanks bartus11. I forgot to mention that the line "may" also start with a letter; how do I modify the awk command?
It should work in that case too.
kurumi
5
tr "\n" "," <file|sed "s/,/','/g;s/''/'/g;s/,'[ \t]*/,'/g;s/','$/'/"
Modified bartus11 code.
awk -vORS=" , " '{gsub("[^0-9a-zA-Z]","");print"#"$0"#"}' file1 | tr "#" "'"
OR
awk -vORS=" , " '{gsub("[[:alnum:]]","");print"#"$0"#"}' file1 | tr "#" "'"