Unix remove white spaces/tabs before & after pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix remove white spaces/tabs before & after pattern
# 1  
Old 07-25-2011
Unix remove white spaces/tabs before & after pattern

Hi All,

I wanted to know is there any way we can remove white spaces/tabs before & after some pattern { eg. before & after "," }.

Please find below sample data below,

Code:
Sat Jul 23 16:10:03 EDT 2011   ,    12345678 , PROD     , xyz_2345677          , testuuyt                       ,      149693 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu
Jul 22 2011                    ,        NULL , PROD     , yt12345              , testuuytoy                     ,      162469 , abtryu

Please help.
# 2  
Old 07-25-2011
Hi,

Using 'perl':
Code:
$ perl -pe 's/\s*,\s*/,/g' infile
Sat Jul 23 16:10:03 EDT 2011,12345678,PROD,xyz_2345677,testuuyt,149693,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu
Jul 22 2011,NULL,PROD,yt12345,testuuytoy,162469,abtryu

Regards,
Birei
This User Gave Thanks to birei For This Post:
# 3  
Old 07-25-2011
Through Sed..
Code:
sed 's/ *, */,/g' inputfile

This User Gave Thanks to michaelrozar17 For This Post:
# 4  
Old 07-25-2011
Thanks a lot ... both ways worked perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Remove White spaces from teh beginnning from a particular row

Hi All, $sed -n "58p" sample 1222017 --- Its has to display like: 1222017 (5 Replies)
Discussion started by: Anamica
5 Replies

2. Shell Programming and Scripting

Remove white spaces from flat file generated from Oracle table...

I have to export data from table into flat file with | delimited. In the ksh file, I am adding below to do this activity. $DBSTRING contains the sqlplus command and $SQL_STRING contains the SQL query. File is created properly with the data as per SQL command. I am getting white spaces in the... (1 Reply)
Discussion started by: mgpatil31
1 Replies

3. Shell Programming and Scripting

Remove spaces / tabs from variable in script

I want to remove extra spaces from variable in aix script. We retrieve the data from oracle database and then print the values. We have a value on 90th position. When we execute the query on sqlplus it shows the length of 90th position as 3, but when we use the same query in aix script it shows... (5 Replies)
Discussion started by: lodhi1978
5 Replies

4. Shell Programming and Scripting

spaces to tabs - group with IP

hi buddies; i have a file.txt: Note: All the seperators are SPACE. 192.168.1.1 ParameterObject=1 Speech 1 ParameterObject=2 Speech 1 192.168.1.1 ParamFunction=1 UserID 1 (DEACTIVATED) Sector=1,Device=2,Unit=3 DeviceId 1 192.168.1.1 FeederCable=2B ... (18 Replies)
Discussion started by: gc_sw
18 Replies

5. Shell Programming and Scripting

How to remove white spaces from the beginning an end of a string in unix?

Suppose, I have a variable var=" name is ". I want to remove the blank spaces from the begining and endonly, not from the entire string. So, that the variable/string looks like following var="name is". Please look after the issue. (3 Replies)
Discussion started by: mady135
3 Replies

6. UNIX for Dummies Questions & Answers

Problem with White spaces and tabs

Hi All, I am facing issues converting white spaces and tabs together in a file I am reading. Here is the command I am trying: tr -s ' '@ | sort -t@ +1n filename I guess the problem is that it is not converting the tabs to another delimiter. Also, I am supposed to accomplish this only using... (5 Replies)
Discussion started by: sh_kk
5 Replies

7. Shell Programming and Scripting

find & dirname:problems with white spaces in Directories

Hi all, my problem: (little extract from my bash-script) I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one); after moving i want to create hardlinks to the old directories. Thatīs no problem, but now: source-directories... (4 Replies)
Discussion started by: tubian
4 Replies

8. Shell Programming and Scripting

spaces or Tabs?

When formatting a script let's say for instance the following: case ${choice} in 1) vi ${tmp1}.tmp # overwrite the tmp1 var with any user changes cp ${tmp1}.tmp ${tmp1} ;; ... (2 Replies)
Discussion started by: llsmr777
2 Replies

9. Linux

How do i remove commas(,) & spaces

Hey guys, I am very much new to shell scripts. So you ppl may feel that i am asking stupid question here. :D 1. I am using command line argument as an input variable. The user gets this value in his mail from client which has commas n spaces (Eg. 12,34,56,789) and the scripts... (5 Replies)
Discussion started by: anushree.a
5 Replies
Login or Register to Ask a Question