I have a flat tab delimited file of the following format
1 A:23 A:45 A:789
2 A:2 A:47
3 A:78 A:345 A:9 A:10
4 A:34 A:98
I want to modify the file to the following format with insertions of "//" in between
1 A:23 // A:45 // A:789
2 A:2 // A:47
3 A:78 // A:345 // A:9 // A:10
4 A:34 // A:98
I tried the following regular expression comment
%s/ /\/\//ig
what I got is:
1 A:23//A:45//A:789
2 A:2//A:47
3 A:78//A:345//A:9//A:10
4 A:34//A:98
What I need is space before and after '//'. Is there a way to do it or modify the regular expression command. Please let me know
# cat test
1 A:23 A:45 A:789
2 A:2 A:47
3 A:78 A:345 A:9 A:10
4 A:34 A:98
# sed 's!\t! // !g' test
1 A:23 // A:45 // A:789
2 A:2 // A:47
3 A:78 // A:345 // A:9 // A:10
4 A:34 // A:98
regards
ygemici
With GNU Sed
sed 's| \+| // |2g' inputfile
One more way...
$ cat input_file | tr -s '[\t]' '//' | sed 's,\/, \/\/ ,g'
1 A:23 // A:45 // A:789
2 A:2 // A:47
3 A:78 // A:345 // A:9 // A:10
4 A:34 // A:98
try this
sed 's/ / \/\/ /g' file
give the space before and after the '/'
thanks
birei
7
Hi,
Using 'perl':
$ perl -lane 'printf "%s %s\n", shift @F, join " // ", @F' infile
1 A:23 // A:45 // A:789
2 A:2 // A:47
3 A:78 // A:345 // A:9 // A:10
4 A:34 // A:98
Regards,
Birei
nawk -F"\t" '{ for(i=1;i<=NF;i++){ printf("%s \\\\ ",$i); if(i==NF) printf("\n");}}' test