- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting: How to locate a colon sign on each fiel...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 08:25 PM
06-06-2006 08:25 PM
Please help. I have a plain file call "file1" as below:
#more file1
AECSIOA Control/M FORCEVILLE/S.
AUTOIOA monitoring FISHER/TL/1 schedule Automation owned jobs in controlM
BTCHDMY Wella BORCHARD/D exchange of order delivery confirmations and statistics data
for Wella
CD1PROD CONNECT DIRECT CALCANEO/M Support Account
COINIOA COINS TOYOURA/Y
ECS0IOA ECS VANDERSTEEN/J
ECS3IOA ECS VANDERSTEEN/J
ECS4IOA ECS VANDERSTEEN/J
ECS8IOA ECS VANDERSTEEN/J
EMFGIOA EMFG WAID/RT batch user for global eManufacturing
Using a shell script, how can I make the output to locate a colon sign(:) on each field. So the output looks like below:
AECSIOA:Control/M:FORCEVILLE/S.
AUTOIOA:monitoring:FISHER/TL/1:schedule Automation owned jobs in controlM
BTCHDMY:Wella:BORCHARD/D:exchange of order delivery confirmations and statistics data for Wella
CD1PROD:CONNECT DIRECT:CALCANEO/M:Support Account
COINIOA:COINS:TOYOURA/Y
ECS0IOA:ECS:VANDERSTEEN/J
ECS3IOA:ECS:VANDERSTEEN/J
ECS4IOA:ECS:VANDERSTEEN/J
ECS8IOA:ECS:VANDERSTEEN/J
EMFGIOA:EMFG:WAID/RT:batch user for global eManufacturing
Please help. High score will be given. Thanks in advance.
Best Regards,
Dewa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 08:42 PM
06-06-2006 08:42 PM
Solutionor Support Account
If you have mixed replacements - and do not have any criteria to define/identify when to replace and when not to atleast for me it seems pretty difficult to do so.
If you can provide any rules that you can formulate then probably it may be possible to help.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 08:56 PM
06-06-2006 08:56 PM
Re: Scripting: How to locate a colon sign on each field
Far from perfect cause of the criteria you gave.
# cat file1 | awk '{ print $1":"$2":"$3":"$4" "$5" "$6" "$7" "$8 $9 $10 $11 $12 }'
Regards,
Robert-Jan
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 09:05 PM
06-06-2006 09:05 PM
Re: Scripting: How to locate a colon sign on each field
Dont you think that the CONNECT DIRECT line will show as
CONNECT:DIRECT instead of
CONNECT DIRECT as required by user.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 09:11 PM
06-06-2006 09:11 PM
Re: Scripting: How to locate a colon sign on each field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 09:15 PM
06-06-2006 09:15 PM
Re: Scripting: How to locate a colon sign on each field
Thanks a lot for your input.
Hi Ninad,
Let me make it simpler. Let say I have this line on the file1:
CD1PROD CONNECT DIRECT CALCANEO/M Support Account
I need the output as below
CD1PROD:CONNECT DIRECT:CALCANEO/M:Support Account
Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 09:36 PM
06-06-2006 09:36 PM
Re: Scripting: How to locate a colon sign on each field
Eureka !!!
Here you go
awk '{if(match($3,"/") == 0) {print $1":"$2$3":"$4$5$6$7$8} else {print $1":"$2":"$3":"$4$5$6$7$8}}' filename | tr -s ":" ":" | sed 's/:$//g'
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 09:42 PM
06-06-2006 09:42 PM
Re: Scripting: How to locate a colon sign on each field
what is the rule? What is a 'field'? Is it possible to adapt the creator of this file?
It looks 'word' based, but is isn't. It seems you want to replace a space between the first three (or four?) fields, but you have exceptions based on the contents of the fields. 'CONNECT DIRECT' is an exception, but there are probably more exceptions?
Maybe use awk as suggested and afterwards replace CONNECT:DIRECT by CONNECT DIRECT?
(cat file | awk .... | sed 's/CONNECT:DIRECT/CONNECT DIRECT/')
How many lines will you process, how often?
of in awk have something like:
if ($2 != "CONNECT" && $3 != "DIRECT") {
...
} else {
print $1":CONNECT DIRECT:"$3":".....
}
If you have multiple exceptions use the following construct:
/CONNECT DIRECT/ {print ...; next}
How is your awk knowledge?
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2006 10:44 PM
06-06-2006 10:44 PM
Re: Scripting: How to locate a colon sign on each field
#perl -pe s/ /:/;s/ (\w+\/\S+)/:$1:/;s/:$//' x.txt
1) -pe = loop over input, read into $_, print.
2) s/ /:/ = change first space into colon
3) s/ (\w+\/\S+)/:$1:/ = look for space, start remembering, followed by some word followed by a slash and anthything that is not blank, stop remembering. Replace by colon-remembered-colon
4) strip colon from end of line
yuck.
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2006 12:09 AM
06-07-2006 12:09 AM
Re: Scripting: How to locate a colon sign on each field
One modification - I have displayed only till $8 - but you check what is the max no. of words and then modify my suggestion to include the extra $..
e.g. if you have 15 words max in a line then
awk '{if(match($3,"/") == 0) {print $1":"$2$3":"$4$5$6$7$8$9$10$11$12$13$14$15} else {print $1":"$2":"$3":"$4$5$6$7$8$9$10$11$12$13$14$15}}' filename | tr -s ":" ":" | sed 's/:$//g'
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2006 12:52 AM
06-07-2006 12:52 AM
Re: Scripting: How to locate a colon sign on each field
Thanks a lot for your help.
I got the point. It looks fine for me now.
Thanks again all.
Best Regards,
Dewa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 11:38 AM
08-25-2006 11:38 AM
Re: Scripting: How to locate a colon sign on each field
As I saw your question today, because I am a new member.
I think no need to do much research for above issue.
Please try below command :
cat file1|awk '{print}'|tr -s " " ":"
If you want to create new file with separator as a colon(:) then do
cat file1|awk '{print}'|tr -s " " ":" > file2
Please let me know in case of any further querry.
Regards
Santosh Kumar Pandey
Hyderabad (India)
Mobile :+91 9866887806
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2006 03:30 PM
08-25-2006 03:30 PM
Re: Scripting: How to locate a colon sign on each field
>> As I saw your question today, because I am a new member.
Welcome to the PH HPUX ITRC Forums.
Please spent some time just looking around and take a moment to read the FAQ.
You will notice that a question marked with a 'bunny' such as this one is a "Message with a response that solved the author's question".
No further reply is needed or expected.
>>> cat file1|awk '{print}'|tr -s " " ":"
Your suggested solution will replace each and every space by a colon. If you read the question and responses carefully, then you will notice this is not what is requested.
Furthermore... why 'cat' the file into awk?
Awk is perfecty capable of finding the file and reading it directly... faster so,
And why go through awk iin the first place?
All you ask awk to do is print each line as read?!
So your suggested solution functionally equals a plain 'tr -s " " ":"', but with a 3 times the resources consumed.
Best regards,
Hein.
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2011 10:05 AM
10-31-2011 10:05 AM
Re: Scripting: How to locate a colon sign on each field
I entered the AWK site and this was the first thread that appear in the list. I know this thread is marked as "solved" and is old but, I think this solution will help some people.
The way to do it in AWK is with gsub:
# awk '{gsub(/ /,":");print}' your_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2011 01:19 PM
10-31-2011 01:19 PM
Re: Scripting: How to locate a colon sign on each field
>The way to do it in awk is with gsub:
Have you read all of the replies? This was rejected as being wrong and also slower than tr(1).