Separate a line to columns using several spaces (>1) as a delimiter using C++ or linux -


i have several lines looking this:

4539(random number of spaces)07235001(random number of spaces)aach(random number of spaces)trier saarburg

i want separate 4 columns using c++ or linux. output want this:

4539|07235001|aach|trier saasburg

so want treat several spaces delimiter not single one.

(random number of spaces thankfully > 1)

lines not consist of 4 columns , space problem not @ last column.

thanks in advance

you can use awk regular expressions this:

echo "4539     07235001      aach    trier saarburg" | awk 'begin { fs = "[ ]{2,}"  } { ofs = "|" };  {$1=$1; print $0 }'  

fs variable used set field separator each record , may contain regular expression. ofs output equivalent of fs variable.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

android - IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html) -