I am new to UNIX Shell scripting.
I need help in removing leading and trailing blank spaces from the fields. But I need to retain the spaces between the words.
Please have a look at the data sample and the desired result below to understand my problem.
Data Sample :
1-B48980007 |82984788|317 |ALQ| |4423271 | 0| |
I0000000000000000000245729|28887957|IL FR | | |00000000573| 0| |
I0000000000000000000245715|13822348|RPVIPPR | | |00000000298| 0| |
I0000000000000000000245721|15348717|AN BV | | |00000001526| 0| |
Desired Result:
1-B48980007|82984788|317|ALQ||4423271|0||
I0000000000000000000245729|28887957|IL FR|||00000000573|0||
I0000000000000000000245715|13822348|RPVIPPR|||00000000298|0||
I0000000000000000000245721|15348717|AN BV|||00000001526|0||
But I am getting the output as below on using the below command:
sed ‘s/ *\|/\|/g’ file_name > testOP
pipeline(‘|’) is a delimiter in my file. I need to remove the spaces before and after the pipeline but need to retain the spaces between the words for example: “IL FR” and “AN BV”.
1-B48980007 |82984788|317|ALQ||4423271| 0||
I0000000000000000000245729|28887957|IL FR| ||00000000573| 0||
I0000000000000000000245715|13822348|RPVIPPR| ||00000000298| 0||
I0000000000000000000245721|15348717|AN BV| ||00000001526| 0||
Any help is greatly appreciated.
Thanks,
Savitha
I resolved the issue with the below sed statement:
sed -e
's/ *\|/\|/g'-e's/press_tab_key_here*\|press_tab_key_here*/\|/g'-e's/\| */\|/g'file_nameto remove the tab spaces, I had to press “tab” key. ‘\t’ didn’t work in my case.
Thanks Michael, Potong and Triplee for all the help and support. 🙂