Hi,
00000119EEEC3F25 feedoor 20171103
0000011A4F152077 feedard 20171024
00000191FA295F61 feedzipperhola 20171023
00000213C57BB856 feedriodapple 20171005
0000025F778EF9D5 joobakoolrk 20171004
I needed the result as:
"00000119EEEC3F25", "feedoor", "20171103",
"0000011A4F152077", "feedard", "20171024",
"00000191FA295F61", "feedzipperhola", "20171023",
"00000213C57BB856", "feedriodapple", "20171005",
"0000025F778EF9D5", "joobakoolrk", "20171004",
I tried using
sed 's/^/"/g file.txt
- Just gets me
"
at the beginning only..
Can someone advise how do I get the needed result? Thanks!
RudiC
2
Are those "gaps" <TAB> chars or multiple spaces? Should they be preserved as is?
Yes tabs and no need to preserve it.
Hello ashokvpp,
Could you please try following and let me know if this helps you.
Solution 1st: In case you don't want TAB as delimiter then following may help you.
awk '{for(i=1;i<=NF;i++){$i=s1 $i s1 s2}} 1' s1="\"" s2="," Input_file
Solution 2nd: In case you need TAB as a output delimiter.
awk '{for(i=1;i<=NF;i++){$i=s1 $i s1 s2}} 1' s1="\"" s2="," Input_file | column -t
Output will be as follows.
"00000119EEEC3F25", "feedoor", "20171103",
"0000011A4F152077", "feedard", "20171024",
"00000191FA295F61", "feedzipperhola", "20171023",
"00000213C57BB856", "feedriodapple", "20171005",
"0000025F778EF9D5", "joobakoolrk", "20171004",
Thanks,
R. Singh
1 Like
Scott
5
A sed one:
sed 's/ /", "/g;s/^/"/;s/$/"/' file
1 Like
RudiC
6
Be it as it may - try
sed 's/[[:space:]]\+/",&"/g; s/^/"/; s/$/",/' file
1 Like
Also try:
sed 's/[^[:blank:]]\{1,\}/"&",/' file
--
GNU sed:
sed 's/[^ \t]\+/"&",/g' file
1 Like
The *
(match zero or more) is problematic here.
The proper replacement for \+
is \{1,\}
sed 's/[^[:blank:]]\{1,\}/"&",/g' file.txt
--
The following variant adds quotes and comma only if not yet present
sed '
s/^\([^"]\)/"\1/
s/\([^",[:blank:]]\)\([[:blank:]]\)/\1",\2/g
s/\([[:blank:]]\)\([^"[:blank:]]\)/\1"\2/g
s/\([^",]\)$/\1",/
' file.txt
2 Likes
Aia
9
perl -pe 's/(\w+)/"$1",/g' ashokvpp.file
Output:
"00000119EEEC3F25", "feedoor", "20171103",
"0000011A4F152077", "feedard", "20171024",
"00000191FA295F61", "feedzipperhola", "20171023",
"00000213C57BB856", "feedriodapple", "20171005",
"0000025F778EF9D5", "joobakoolrk", "20171004",
1 Like
You are right of course. That was a copy-paste error
1 Like