Space formatting issue in sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Space formatting issue in sed
# 1  
Old 11-02-2010
Space formatting issue in sed

How to remove any space around a specific charachter from a string using sed.

for exmple :
the string is like following
Code:
str1='"name", "roll", "addr","job", "pay",'

I need to remove all the spaces aronnd the commas.
# 2  
Old 11-02-2010
simplest usage
Code:
# sed 's/ "/"/g' infile

# 3  
Old 11-02-2010
Code:
echo "$str1" | sed 's/ *, */,/g'

# 4  
Old 11-02-2010
not working

its giving the message :
Code:
try.sh[7]: str4=${echo $str1 | sed "s/ *, */,/g"}: bad substitution

# 5  
Old 11-02-2010
Hi, use $( ) instead of ${ } (and use double quotes around $str1)
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-02-2010
with tr ..
Code:
echo "$str1"|tr -d " "

# 7  
Old 11-02-2010
Try with ( )
Code:
str4=$(echo $str1 | sed "s/ *, */,/g")

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Solaris

Syslog formatting issue

Hi, I am using log4j syslog appender to redirect the application logs to the solaris syslog. However, I am facing issue in formatting. It is not able to interpret new line characters and is printing \n as it is. Ex: Following is getting written into the syslog file. "\n \n File =... (4 Replies)
Discussion started by: Pra
4 Replies

3. Windows & DOS: Issues & Discussions

email from *nix to Exchange - text formatting issue

Oracle Linux 5.6 x-86-64 (Red Hat derivitive) I have several shell scripts that capture output to a log file, then use that log file as the source of an email. For a very simplified example: echo Today is `date` >> $logfile /bin/mail -s "$subject" "$sendto" < $logfile (yes, $subject... (6 Replies)
Discussion started by: edstevens
6 Replies

4. Shell Programming and Scripting

Need solution to formatting issue

Hi All, I have written a grep command to grep the files containing Windows directories. I need to output this to a csv. So here is the code. OUTPUT_FILE="Sample-format.txt" ACT_OUTPUT_FILE="Sample-format.csv" grep -wHrnI --exclude=*.log ':\{1,2\}*\{1,2\}*'... (0 Replies)
Discussion started by: flamingo_l
0 Replies

5. Shell Programming and Scripting

Formatting issue

I am running this query in a SQL session : info_dtls=`sqlplus -s / <<eof whenever sqlerror exit 1 set feedback off; set verify off; set echo off; set heading off; select trim(a.cont_title)||'","'||trim(b.cpgrp_desc)|| '","'||trim(to_char(to_date('20100930','yyyymmdd'),'MM/DD/YYYY'))||... (1 Reply)
Discussion started by: mady135
1 Replies

6. Shell Programming and Scripting

Formatting Help needed(Sed)

I have a file called abc.txt which has following contents. 10.180.8.231=31608 10.180.8.232=29011 10.180.8.233=31606 10.180.8.234=40501 10.180.8.235=32591 10.180.8.236=31605 10.180.8.237=30561 10.180.8.238=14231 How would i find a ip address having maximum number of ram available. Here... (2 Replies)
Discussion started by: pinga123
2 Replies

7. Shell Programming and Scripting

sed formatting query

had asked this earlier , but now with some small modification. i wish to remove "#" characters and replace them with a single # character. how to do that? . like # should be appended in all lines ex if the file is like ####aasd ##pqr #qwert poppy output shud be #aasd #pqr #qwert... (2 Replies)
Discussion started by: gopsman
2 Replies

8. Shell Programming and Scripting

sed formatting query2

i wish to remove "#" characters and replace them with a single # character. how to do that? ex if the file is like ####aasd ##pqr ###pqr #qwert output shud be #aasd #pqr #pqr #qwert plz hlp (4 Replies)
Discussion started by: gopsman
4 Replies

9. Shell Programming and Scripting

sed formatting query

hi i have to modify a number accross a file for example in the following file name - abc age 20 name - def age 25 name - pqr age 54 name - xyz age 32 i want the number against all age to be say 50. like this name - abc age 50 name - def (2 Replies)
Discussion started by: gopsman
2 Replies

10. UNIX for Dummies Questions & Answers

formatting space usage/available reports

I'm really, really new to writing scripts, but have been asked to generate a report that will show available space for a disk, space used by particular subdirectories on the disk and totals. I can get the information I need with du and df and output it to a text file but I'm stumped as to how to... (3 Replies)
Discussion started by: DesperateDBA
3 Replies
Login or Register to Ask a Question