sed Command new Line not working Tried many variations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Command new Line not working Tried many variations
# 8  
Old 01-20-2014
Hello,

Code:
echo $a | awk 'gsub(/overflow condition\. /,"overflow condition\.\n")1'

Output will be as follows.

Code:
pwrm16: Info: Thu Dec 12 22:20:23 2013 User PWPYNYFWD01 at position 170.198.8.160/net on host 170.198.8.160 using application 257 has been disconnected due to an overflow condition.
pwrm17: Info: Sun Dec 15 21:37:30 2013 User PWPYNYFWD01 at position 170.198.8.160/net on host 170.198.8.160 using application 257 has been disconnected due to an overflow condition.
pwrm18: Info

Hope this may help.


Thanks,
R. Singh
# 9  
Old 01-20-2014
There must be an easier way to do this?
I can strip off the colon before I pass it to the variable
All I need to do is to print the variable every time the host appears
For simplicity lets just make the same host the same name

printf "$i " | sed or Awk command here to insert a new line everytime I encounter the host name .

So the input variable is ( same hostname host01)

i=host01 text goes here 1 host01 text goes here 2
printf "$i " | sed or awk here to find the hostname and then insert a line after the host name and print the content on new line
output

Code:
host01  textgoes here 1
host01 textgoes here 2


Last edited by Scrutinizer; 01-20-2014 at 07:44 PM.. Reason: code tags
# 10  
Old 01-20-2014
Try
Code:
HOST=pwrm
sed -r "s/($HOST[^[:space:]]*):/\n\1/g" <<<"$I"

pwrm16 Info: Thu Dec 12 22:20:23 2013 User PWPYNYFWD01 at position 170.198.8.160/net on host 170.198.8.160 using application 257 has been disconnected due to an overflow condition. 
pwrm17 Info: Sun Dec 15 21:37:30 2013 User PWPYNYFWD01 at position 170.198.8.160/net on host 170.198.8.160 using application 257 has been disconnected due to an overflow condition.

or
Code:
echo "$I" | sed -r "s/($HOST[^[:space:]]*):/\n\1/g"

# 11  
Old 01-20-2014
This code is working for me thanks for ur replies

This was the simplest resolution I had .. Thank u all for ur replies

sed -E 's/://;s/(\w+):/\n\1/g' <<< "$var1"
abc001 text goes here yyy003 text goes here uuuu004 text goes here

SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove matching pattern on each line with number variations

Hello folks! I have a file containing lines like this Something text 18:37Remove This: 1,111"Keep this text" Some more text 19:37Remove This: 222"Keep this text" More text 20:50Remove This: 3,333Keep this text And more text 25:50Remove This: 44,444Keep this text I would like to... (4 Replies)
Discussion started by: martinsmith
4 Replies

2. Shell Programming and Scripting

sed command not working

cat bipin.txt Unix is an OS Unix has its own commmands Unix is a user friendly OS Unix is platform independent Unix is a time sharing OS the best OS to learn is Unix Abinitio uses Unix in backend this is my file when i use sed 's/Unix/Linux/' bipin.txt all the occurences are getting... (0 Replies)
Discussion started by: Bipin_1991
0 Replies

3. Shell Programming and Scripting

sed working on command line but file unchanged when execute with Shell script

I have a simple task to replace unix line feed end of line characters with carriage returns. When I run the following “change file in place” sed instruction from the command line all the Line feeds are successfully replaced with Carriage returns. sed -i 's/$/\r/' lf_file.txt But that same... (1 Reply)
Discussion started by: hawkman2k
1 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

sed adding a new line not working

sed '/patternstring/ a\ new line string' file1 The above code is not working even with the i option.... it shows sed grambled if '\' after new line string is not being used....after using no changes it is displaying..Pls help (5 Replies)
Discussion started by: bhavanabahety
5 Replies

6. Shell Programming and Scripting

sed adding a new line not working

The file which is used is /abc/apps/cobbbbbb/apps/abadv/binder/axyz.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/na6115.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/kc22.bnd /abc/apps/cobbbbbb/apps/abbrio/binder/tr4823.bnd /abc/apps/cobbbbbb/apps/abcmp/binder/cpc0105.bnd The commads which I ran... (3 Replies)
Discussion started by: bhavanabahety
3 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

Sed: Working on a line Previous to a pattern.

Hello everyone, I am working with some train time tables, and i have hit a bit of a road block. Using grep/sed i have done a reasonable job of parsing the html into comma delimited format, but NJ transit prints The Track number and status on a new line, and I would much prefer it all on a... (6 Replies)
Discussion started by: mussen
6 Replies

9. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

10. Shell Programming and Scripting

using sed to replace a line is not working

This is what I have this far rsh server1 "cat /home/test.txt |sed s/01-jun-2009/01-aug-2009/ |sed s/ABCD/1234/" but it is not working is there something I am doing wrong in my syntax? The file test.txt is the same on all of my 15 servers it has the same length and contents only certain... (3 Replies)
Discussion started by: deaconf19
3 Replies
Login or Register to Ask a Question