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 04:39 PM..
$ cat file
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.
Code:
$ awk 'gsub(host_prefix,"\n\n&")' host_prefix=pwrm file
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.
Hi thanks for ur responses .. I will try these and get back to u when I get to work tomorrow .. I try to set a virtual host and try it now
good day
---------- Post updated at 02:52 PM ---------- Previous update was at 02:46 PM ----------
Ashkey Hedge .. I do not have a file to cat . I ssh to certain hosts and get that information from log file and assign it to A variable so I'm not sure what u mean bu catting the file? I can read the variable.
also the host . I'm not sure what you mean by this?
host prefix is pwrm and a number. It can be anything from pwrm01 through pwrm19 ..
awk 'gsub(host_prefix,"\n\n&")' host_prefix=pwrm <<<$Variable
so I'm not sure how this will work. Maybe I'm missing soething here but not sure what toi substitute the host_prefix with as it will change .?
cfajohnson ,, Thanks for ur reply .. I just tested the reassignment of the variable and it works great. But please remember , I have to print everything after the hostname until the occurence of the next host name on a new line. You reply does not address my question in full though is very useful ...So the output should be.
my input is assigned to variable i is as follow :
hostname1: text goes here hostname2: text goes here hostname3: text goes here
The output should be:
hostname1 text here
hostname2 text here
hostname3 text here
---------- Post updated at 03:04 PM ---------- Previous update was at 03:01 PM ----------
Ravindersingh13 - Thanks for ur reply .. I appreciate the perl command. But I won;t be able to use it in this script. I need to use the shell command to do this. Can you help with a shell command:
my input is assigned to variable i is as follow :
hostname1: text goes here hostname2: text goes here hostname3: text goes here
The output should be:
hostname1 text here
hostname2 text here
hostname3 text here
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)