Shell script: Removing leading and trailing spaces between fields in a pipe delimited file
I have a pipe delimited file as below
1 |Mike | 2000| 2|
2 |Peter | 4000| 2|
..... ... .... and so on.
I want to remove the leading and trailing spaces between fields. It should look like as below
1|开发者_JS百科Mike|2000|2|
2|Peter|4000|2|
Is there any way in shell script to achieve this output?
Thanks, Chandraa
You can try
cat datafile | tr -d ' \t'
cat datafile | tr -d '[:space:]' # will remove all spaces including the new line at the end of each line
Try this:
cat datafile | sed -e 's/[ \t]*|[ \t]*/|/g'
精彩评论