Sponsored Content
Top Forums Shell Programming and Scripting sed Command new Line not working Tried many variations Post 302884269 by mnassiri on Sunday 19th of January 2014 02:16:18 PM
Old 01-19-2014
sed Command new Line not working Tried many variations

Hi

I have assigned an output of a command to $I. I try to print the input and put a new line after occurrence of the hostname which is assigned to $HOST1 ( Example: pwrm16 ) . First of all I need to get rid of the Colon after the host name pwrm16: and make it pwrm16 then I want to print the rest of the line until I hit another hostname. In short I need to get rid of the the colon before the host pwrm16: and then print the line from the string until I get to the next host name . Can someone please help me ? Tried my best and wasted a lot of times


***********************************
I want the output be in this format:


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.

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

*****************************************

I can get rid of the colon by using tr and reassign it ti the variable. However
I just have not able to print anything on a new line. It just not working. I went on internet and tried everything I could find. Just don't seem able to print anything on a new line. Basically all I get is the entire string.

Current command I'm using ( used so many difference variations )
Code:
printf "$I "| sed 's/$HOST1/\n/g'
$HOST1 = pwrm16


*****************************************

Current output I get is as follow

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: Wed Dec 18 11:31:43 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. pwrm16: Info: Wed Dec 18 14:00:05 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. pwrm16: Info: Thu Jan 02 13:51:24 2014 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. pwrm19: Info: Fri Jan 17 01:16:26 2014 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. pwrm16: Info: Fri Jan 17 03:39:19 2014 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.

********************************************

Last edited by Scrutinizer; 01-19-2014 at 03:39 PM..
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 04:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy