sed formatting query2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed formatting query2
# 1  
Old 05-09-2007
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
# 2  
Old 05-09-2007
Code:
sed 's/##*/#/g' filename

# 3  
Old 05-09-2007
Code:
sed 's/#\{1,\}/#/g' file

# 4  
Old 05-09-2007
Hi.

With some versions of sed you can use extended regular expressions, which can make the often inscrutable sed scripts slightly easier to read. Either as shown here or with -r:
Code:
#!/bin/sh

# @(#) s1       Demonstrate extended regular expressions in sed.

FILE=${1-data1}

sed --regexp-extended 's/#+/#/g' $FILE

Producing on your data in data1:
Code:
% ./s1
#aasd
#pqr
#pqr
#qwert

cheers, drl
# 5  
Old 05-10-2007
Code:
tr -s '#' < filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies

2. Shell Programming and Scripting

Formatting Help

Hi Guys, i have report that runs every 10 min and send the report of failed jobs to my mail. Currently i am using a command like this to send mail. mailx -t -s "FAILURE JOBS IN HYDRA $temp_date" addressee@domain.com < temp_file5 But i am getting mail in this format ....... (4 Replies)
Discussion started by: gkrish
4 Replies

3. Shell Programming and Scripting

help formatting

I need to format a txt file and convert it in CSV. Any "future" column is separated by a newline. FROM: XS1 1.43294 0.0 XS2 1.21824 0.0 TO: XS1,XS2 (2 Replies)
Discussion started by: alfreale
2 Replies

4. Shell Programming and Scripting

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 str1='"name", "roll", "addr","job", "pay",' I need to remove all the spaces aronnd the commas. (8 Replies)
Discussion started by: mady135
8 Replies

5. Shell Programming and Scripting

Formatting help needed awk or sed maybe

I am executing the following command: sort file1.txt | uniq -c | sort -n > file2.txt The problem is that in file 2, I get leading spaces, Like so: 1 N/A|A8MW11 8 N/A|ufwo1 9 N/A|a8mw11 10 900003|smoketest297688 10 N/A|a9dg4 10 danny|danni 12... (5 Replies)
Discussion started by: ddurden7
5 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

formatting data file with awk or sed

Hi, I have a (quite large) data file which looks like: _____________ header part.. more header part.. x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 ... ... x59 x60 y1 y2 y3 y4... ... y100 ______________ where x1, x2,...,x60 and y1, y2,...y100 are numbers of 10 digits (so each line... (5 Replies)
Discussion started by: lego
5 Replies

8. 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

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

I've been asking on IRC channels but no one answers me, I need to format my hard drive, normally it's just format c: but c doesn't exist, how do I format when I have linux mandrake installed. Please reply to this quickly, I'm kinda in a rush :( (1 Reply)
Discussion started by: darryll777
1 Replies
Login or Register to Ask a Question