Removing blanks, spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing blanks, spaces
# 1  
Old 07-03-2012
Removing blanks, spaces

I have pipe separated file with lots of blank spaces.

After using sed -e 's/ *| */|/g' this command ,its giving me output as

Code:
TT0000013101640|
         HCAMBLAMCNB010|Jul  3 2012 11:14AM|
         HARYANA|
         Bangali Mohalla |
         TCL-UBR|9368040005|9355264655|9218509220|NULL 
 TT0000013101695|
         QCKNKEKKUIB001|Jul  3 2012 11:17AM|
         JHARKHAND|
         Kathkamkuli|
         Uninor|9386897706|7488049301|9122112522|NULL 
 TT0000013101724|
         MCSLOOSLOOB001|Jul  3 2012 11:18AM|
         MAHARASHTRA + GOA|
         SELOO|
         TULIP|9325405402|9325406984|9953194983|NULL

But I want O/P in one line. Kindly suggest a query.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.


---------- Post updated at 01:25 AM ---------- Previous update was at 01:14 AM ----------

Ok...But plz reply now for my query

---------- Post updated at 01:25 AM ---------- Previous update was at 01:25 AM ----------

Ok...But plz reply now for my query

Last edited by zaxxon; 07-03-2012 at 03:24 AM.. Reason: code tags
# 2  
Old 07-03-2012
Hi


Code:
$ cat file
TT0000013101640|
         HCAMBLAMCNB010|Jul  3 2012 11:14AM|
         HARYANA|
         Bangali Mohalla |
         TCL-UBR|9368040005|9355264655|9218509220|NULL
 TT0000013101695|
         QCKNKEKKUIB001|Jul  3 2012 11:17AM|
         JHARKHAND|
         Kathkamkuli|
         Uninor|9386897706|7488049301|9122112522|NULL
 TT0000013101724|
         MCSLOOSLOOB001|Jul  3 2012 11:18AM|
         MAHARASHTRA + GOA|
         SELOO|
         TULIP|9325405402|9325406984|9953194983|NULL

Code:
$ sed 's/^ *//' file | awk '/\|$/{printf $0;next}1'
TT0000013101640|HCAMBLAMCNB010|Jul  3 2012 11:14AM|HARYANA|Bangali Mohalla |TCL-UBR|9368040005|9355264655|9218509220|NULL
TT0000013101695|QCKNKEKKUIB001|Jul  3 2012 11:17AM|JHARKHAND|Kathkamkuli|Uninor|9386897706|7488049301|9122112522|NULL
TT0000013101724|MCSLOOSLOOB001|Jul  3 2012 11:18AM|MAHARASHTRA + GOA|SELOO|TULIP|9325405402|9325406984|9953194983|NULL

# 3  
Old 07-03-2012
One more way .. (Based on the input given)
Code:
$ nawk '{$1=$1};1' infile | paste -d" " - - - - -
TT0000013101640| HCAMBLAMCNB010|Jul 3 2012 11:14AM| HARYANA| Bangali Mohalla | TCL-UBR|9368040005|9355264655|9218509220|NULL
TT0000013101695| QCKNKEKKUIB001|Jul 3 2012 11:17AM| JHARKHAND| Kathkamkuli| Uninor|9386897706|7488049301|9122112522|NULL
TT0000013101724| MCSLOOSLOOB001|Jul 3 2012 11:18AM| MAHARASHTRA + GOA| SELOO| TULIP|9325405402|9325406984|9953194983|NULL
$

# 4  
Old 07-03-2012
Thanks alot for the reply.

Code:
I tried sed 's/^ *//' temp | awk '/\|$/{printf $0;next}1' its giving me error .
awk: syntax error near line 1
awk: bailing out near line 1

Plz help to get out of this
# 5  
Old 07-03-2012
Use nawk for Solaris machines ..
# 6  
Old 07-03-2012
Hi
If your OS is solaris, in place of awk, use nawk, else use /usr/xpg4/bin/awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing spaces between parenthesis ()

Hello, i 've go a file with the following text: oracle@das (J005) 0 oracle@das (J008) 0 oracle@das (J050) 0 oracle@das (J038) ... (15 Replies)
Discussion started by: nms
15 Replies

2. UNIX for Dummies Questions & Answers

Removing spaces in the second field alone

Consider my input string as "abc|b f g|bj gy" I am expecting the output as "abc|bfg|bj gy". Please let me know how to achieve this in unix? Thanks (8 Replies)
Discussion started by: pandeesh
8 Replies

3. Shell Programming and Scripting

removing spaces in filenames

I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command? find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies

4. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

5. Shell Programming and Scripting

Removing spaces in a line

Hi All, I have a line like this " field1;field2;field3 " (single space after and before double quotes). Now i have to remove these single space . Kindly help me. Thanks in advance (2 Replies)
Discussion started by: krishna_gnv
2 Replies

6. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

7. Shell Programming and Scripting

Removing blanks in a text tab delimited file

Hi Experts I am very new to perl and need to make a script using perl. I would like to remove blanks in a text tab delimited file in in a specfic column range ( colum 21 to column 43) sample input and output shown below : Input: 117 102 650 652 654 656 117 93 95... (3 Replies)
Discussion started by: Faisal Riaz
3 Replies

8. Shell Programming and Scripting

Removing spaces from data

Hi, I want to remove spaces from data. Data is: 1,aa ,21, 22 2,a a ,23 ,24 3, ,25 ,26 output should be: 1,aa,21,22 2,a a,23,24 3, ,25,26 i.e i have to remove leading and trailing spaces.Not the space between data and also i dont want to remove the space if data is... (4 Replies)
Discussion started by: monika
4 Replies

9. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

10. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies
Login or Register to Ask a Question