injecting new line in sed substitution (hold space)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting injecting new line in sed substitution (hold space)
# 1  
Old 05-13-2009
injecting new line in sed substitution (hold space)

Morning, people!

I'd like to call upon your expertise again, this time for a sed endeavor.

I've already searched around the forums, didn't find anything that helped yet.

background: Solaris 9.x, it's a closed system and there are restrictions to what is portable to it. So let's assume I can't just download an updated GNU/POSIX utility.

Alright, so I've been reading some literature on Sed and I'm under the impression that it is somehow possible to embed/inject a newline in the hold space (the string replacing a pattern).

the intent was to double space some reports that we produce on weekly basis for a more eye-friendly format.

So we have a line as follows;
Group User ID Day Week End Reports Compl Hours Logged
analysis azzame Week 25APR09 13 26.0 42.7
analysis campbels Week 25APR09 26 51.2 48.2

basically, I was trying to double space lines conforming to the above format. NOTE** there are spaces in front of the lines for formatting in the actual file

so I tried a sed edit like this:

# sed 's/^ *analysis.*[0-9]$/&\
/' wkending25APR09.txt


inspiration for this comes from the following

https://www.unix.com/shell-programmin...character.html
at the bottom of this post, it appears as though embedding a newline is possible.


also, the following excerpt from the following link:

sed

"A line can be split by substituting a <newline> into it. The application shall escape the <newline> in the replacement by preceding it by a backslash. A substitution shall be considered to have been performed even if the replacement string is identical to the string that it replaces. Any backslash used to alter the default meaning of a subsequent character shall be discarded from the BRE or the replacement before evaluating the BRE or using the replacement."


Let me know your thoughts, i.e. if I'm chasing a ghost any alternatives would be greatly appreciated, I came across something like gsub function in awk?? I guess that might make it possible, however if it's possible in sed I would prefer that method purely to satisfy my knowledge curiosity.

thanks, y'all!!
ProGrammar
# 2  
Old 05-13-2009
is it this your expecting ?..

Code:
 
TESTING>cat sed_ip
Group User ID Day Week End Reports Compl Hours Logged
analysis azzame Week 25APR09 13 26.0 42.7
analysis campbels Week 25APR09 26 51.2 48.2

TESTING> sed '
> /Logged/ a\
>
> ' sed_ip >> op
 
TESTING>cat op
Group User ID Day Week End Reports Compl Hours Logged
 
analysis azzame Week 25APR09 13 26.0 42.7
analysis campbels Week 25APR09 26 51.2 48.2

# 3  
Old 05-13-2009
please disregard!

Panyam,

Thanks for your response. I wasn't really looking to embed a newline after the column headers though.

I was interested in double-spacing the rows of data.

Actually,
I was in Csh when attempting to perform that sed edit, naturally it didn't work.

But then I switched over to Bourne (sh) and the edit worked perfectly as written.

I'm sorry for wasting your time.

I guess an admin can close this thread.
# 4  
Old 05-13-2009
Hi ProGrammar,

I see your Problem ist solved, but in general for better readability of columns, try using printf

Code:
awk '{ printf ( "%15-s %15-s %15-s %10-s %4-s %6-s\n",$1,$2,$3,$4,$5,$6,$7) }' yourfile

there is just a problem with the header, but this can be solved by replacing not needed spaces by "-" or similar
# 5  
Old 05-13-2009
Code:
sed 's/ /  /g' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed's hold-space to filter file contents

I wrote an awk script to filter "uninteresting" commands from my ~/.bash_history (I know about HISTIGNORE, but I don't want to exclude these commands from my current session's history, I just want to avoid persisting them across sessions). The history file can contain multi-line entries with... (6 Replies)
Discussion started by: ivanbrennan
6 Replies

2. Shell Programming and Scripting

Hold buffer in sed

Hi Experts, i have a file like below **** table name is xyz row count for previous day 10 row count for today 20 diff between previous and today 10 scan result PASSED **** table name is abc row count for previous day 90 row count for today 35 diff between previous and today 55... (4 Replies)
Discussion started by: Lakshman_Gupta
4 Replies

3. Shell Programming and Scripting

Hold, Replace and Print with sed

Hi, I'm a newbie with scripting so I'd appreciate any help. I have a file import.txt with below text AA_IDNo=IDNoHere AA_Name=NameHere AA_Address=AddressHere AA_Telephone=TelephoneHere AA_Sex=SexHere AA_Birthday=BirthdayHere What I need is that the Lines for Name, Address and... (3 Replies)
Discussion started by: heretolearn
3 Replies

4. Shell Programming and Scripting

sed: hold buffer question

I've been using sed to help with reformatting some html content into latex slides using the beamer class. Since I'm new to sed, I've been reading a lot about it but I'm stuck on this one problem. I have text that looks like this: ******************* line of text that needs to be... (4 Replies)
Discussion started by: tfrei
4 Replies

5. Shell Programming and Scripting

sed pattern and hold space issues

Good day. Trying to make a sed script to take text file in a certain format and turn it into mostly formatted html. I'm 95% there but this last bit is hurting my head finally. Here's a portion of the text- Budgeting and Debt: Consumer Credit Counseling of Western PA CareerLink 112... (5 Replies)
Discussion started by: fiendracer
5 Replies

6. Shell Programming and Scripting

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). #!/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))... (7 Replies)
Discussion started by: jossojjos
7 Replies

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

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

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

10. Shell Programming and Scripting

How to use sed substitution using a $variable for a line containing a word

$ cat ggg /E*Fare/testteam/public/pf3/nggfstatic/4k-pf3_3.case REGION1: /E*Fare/dist/src/nggfstaticbase/EFare/Server CODEBASE1: /dev_tools/LINUXMTP-4/EFS070718E/EFare/Server DATABASE1: nggfstatic SCRIPT: /efare1/admin/ezlcn/scripts/pf3_3_scriptlist.input PROLOGINITSIZE not yet set You... (4 Replies)
Discussion started by: Sangal-Arun
4 Replies
Login or Register to Ask a Question