Sponsored Content
Top Forums Shell Programming and Scripting sed : replace space and end-of-line Post 302405666 by jossojjos on Friday 19th of March 2010 12:41:00 PM
Old 03-19-2010
sed : replace space and end-of-line

Hi !

I'm rather new with sed ... learned a lot already by googling etc ...

The following script should replace all spaces and ends-of-lines with "something (see below).

Code:
#!/bin/bash

i=0
while read line
do 
fam="H`printf "%06d" $i`" 
echo $line | sed -e 's/[$ ]/\t'$fam'\n/g' 
i=$(($i+1)) 
done < $1

However, this only seems to replace the spaces, not the ends-of-line.
If I put only
Code:
echo $line | sed -e 's/$/\t'$fam'\n/g'

it does replace the ends-of-line.

To be more specific, if my file looks like this :

a b c
d e

I want it to become

a H000000
b H000000
c H000000
d H000001
e H000001

If anyone has a suggestion : thanks !
Jos
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to see space, tab, end of the line chracters

what can I use ?? In vi, I can use :set list <-- and see end of line $.. or use cat -A but I am wondering if there is command or program that allows me to see all the hidden characters( space, tab and etc) Please help thanks. (3 Replies)
Discussion started by: convenientstore
3 Replies

2. UNIX for Advanced & Expert Users

how can I read the space in the end of line

cat file1|while read i do echo "$i"|wc done with this command the space in the end of the line not considered how can solve that for example: read h "hgyr " echo "$h"|wc 4 (2 Replies)
Discussion started by: Ehab
2 Replies

3. Shell Programming and Scripting

Replace space, that is not in html tags <> with new line using sed

Hi, I am working on transforming html code text into the .vert text format. I want to use linux utility sed. I have this regexp which should do the work: s/ \(?!*>\)/\n/g. I use it like this with sed: echo "you <we try> there" | sed 's/ \(?!*>\)/\n/g' ... The demanded output should be: you <we... (5 Replies)
Discussion started by: matt1311
5 Replies

4. Shell Programming and Scripting

Add white space to the end of a line with sed

Im trying to add 5 blank spaces to the end of each line in a file in a sed script. I can figure out who o put the spaces pretty much anywhere else but at the end. thanks Karl (7 Replies)
Discussion started by: karlanderson
7 Replies

5. Shell Programming and Scripting

gnu sed replace space with new line

please help in making sed singleline command i need to insert dos new line (CR LF) before " 34 matching device(s) found on \\cpu1." " 6 matching device(s) found on \\cpu7." " 102 matching device(s) found on \\mainserver." the problem is that sometimes there are both CR LF before strings and... (1 Reply)
Discussion started by: xserg
1 Replies

6. Shell Programming and Scripting

how to replace new line ( \n ) with space or Tab in Sed

Hi, how to replace new line with tab in sed ... i used sed -e 's/\n/\t/g' <filename > but its not working (1 Reply)
Discussion started by: mail2sant
1 Replies

7. Shell Programming and Scripting

Replace end of line with a space

for eg: i have i/p file as: ================ i wnt to change end of line ================= my require ouput is like: i wnt to change end of line ==================== (7 Replies)
Discussion started by: RahulJoshi
7 Replies

8. Shell Programming and Scripting

How to Add space at the end of each line in linux

hi,. I am writing a small script in csh... Can any one tel me how to add space at end of each line in a file (9 Replies)
Discussion started by: Manju87
9 Replies

9. Shell Programming and Scripting

simple sed question - replace from phrase to end of line

I have the following line an in input file I want to digest with sed and simple replace the bold part with a variable defined in my bash script. I can do this in several sed operations but I know there must be a way to do it in a single sed line. What is the syntax? Line in file:... (1 Reply)
Discussion started by: graysky
1 Replies

10. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies
FAMD(8) 								SGI								   FAMD(8)

NAME
famd - The File Alteration Monitor (FAM) daemon SYNOPSIS
famd [-CdflLv] [-C conffile] [-p prog.vers] [-t period] [-T timeout] DESCRIPTION
FAM, the File Alteration Monitor, is a subsystem that applications can use to be notified when specific files or directories are changed. It is intended as a replacement for mechanisms such as poll and select. FAM comes in two parts: famd, the daemon that listens for requests and provides notifications, and libfam a library that client applica- tions can use to communicate with FAM. For further information on libfam, see the fam(3) manual page. famd is normally started by an Internet superserver such as inetd or xinetd, but can also be started independently. Only one instance of famd can be run at a time. famd can be configured by editing the famd configuration file (see fam.conf(5) for further details) or by providing the following command line options: OPTIONS
-c conffile Read configuration information from conffile. -C Run in backwards compatibilty mode. This is disables authentication and is not recommended. -f Run in the foreground. -v Enable verbose messages. -d Enable verbose messages and debug messages. -l Disable polling of files on remote NFS servers. -L Only accept connections from local clients. -p prog.vers Register with the portmapper using the specifed RPC program and version numbers. -t period Poll a remove NFS server every period seconds to obtain file updates if the remove server is not running famd. -T timeout Exit timeout seconds after the last client disconnects. A value of 0 causes famd to run forever. SECURITY
famd never opens the files it's monitoring, and only monitors files that the client can stat. FILES
/etc/fam.conf Default famd configuration file. SEE ALSO
fam(3), fam.conf(5), inetd(8), portmap(8), stat(1), xinetd(8) BUGS
famd (fam 2.6.10) January 19, 2003 FAMD(8)
All times are GMT -4. The time now is 07:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy