Computing.Net > Forums > Unix > Substitute - with 1st word line2

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Substitute - with 1st word line2

Reply to Message Icon

Name: Big_Z
Date: June 6, 2005 at 08:30:35 Pacific
OS: AIX 5.1
CPU/Ram: RISC/1GB
Comment:

Hello,

I am running Tivoli Storage Manager command "query event" and trying to basically un-wrap hostnames that are too long.
For a hostname that is longer than a certain amount of characters, a "-" is placed at the end and the last few characters are wrapped to the next line. I want to replace the "-" with the last characters of the hostname which are on the next line. See below

2005/06/06 SERVER- Failed
NAME1

2005/06/06 SERVER1 Completed

2005/06/06 SERVER- Missed
NAME2

The actual hostnames in the example above would be SERVERNAME1, SERVER1, and SERVERNAME2.

If there is a dash, I want to replace it with the first word on the next line, which would be the last characters of the jobname.

I am getting this report with awk, but can't find a way to replace the dash with first word on next line. Nothing needs to be done if no dash is found.

Any suggestions on this one?

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: June 6, 2005 at 08:43:58 Pacific
Reply:

awk '{
dash=index($0,"-")
if (dash==0)
   print
else
  {getline overflow
   print substr($0,1,dash-1) \
      overflow substr($0,dash+1)}
}' filein


0

Response Number 2
Name: Big_Z
Date: June 6, 2005 at 09:39:02 Pacific
Reply:

Worked great, thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Installing FreeBSD on sla... sed problem



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Substitute - with 1st word line2

vi \ ex : Substitute with newline? www.computing.net/answers/unix/vi-ex-substitute-with-newline/6485.html

Replace Word www.computing.net/answers/unix/replace-word/6230.html

replace a newline with string www.computing.net/answers/unix/replace-a-newline-with-string/4658.html