- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl script to replace awk
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
07-26-2004 08:29 AM
07-26-2004 08:29 AM
I just need a kick, and should be on my way.
I have a file that is separated by commas, if I print the file out I would get this...
awk -F, '{print "204"$1","$2","$3}' FILE
The output is
204xxxx001,00 0 05 21,TELN NOT
204xxxx002,00 0 01 30,TELN NOT
204xxxx008,00 0 04 15,TELN NOT
204xxxx013,00 0 02 30,CUST HAS
204xxxx015,00 0 10 22,CUST HAS
I also need to insert data into this line...
204xxxx001,EAST_BLD,ROOM2,00 0 05 21
204xxxx002,EAST_BLD,ROOM2,00 0 01 30
I am just having a difficult time trying to take awk and convert to perl.
I know I can write in bash but I would like to try in perl.
How do I prompt user for input that will insert into the $2, as well as $3.
Basically I want,
Enter BLD:
User enter is EAST_BLD
Enter room:
User enters in ROOM2
Then the perl script takes that info and inserts these fields into every line, as well as adding 204 at the begining and dumping the last field.
And here is a trickier question...
How do I do a grep on CUST and then place those lines in a file
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 08:38 AM
07-26-2004 08:38 AM
Re: Perl script to replace awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 08:38 AM
07-26-2004 08:38 AM
Re: Perl script to replace awk
Man a2p for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 08:45 AM
07-26-2004 08:45 AM
Re: Perl script to replace awk
I can awk -F, '{print "204"$1","$2","$3}' FILE
But I can not...
echo "Enter BLD: "
read $BLD
Then insert it the awk statement...
awk -F, '{print "204"$BLD","$2","$3}' FILE
awk does not like it. Or am I doing something wrong with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 09:47 AM
07-26-2004 09:47 AM
Solution#!/usr/bin/perl
print "Enter BLD:"; $bld=
print "Enter ROOM:"; $room=
while(
chomp;
@a=split(",",$_);
print join(",",$a[0],$bld,$room,$a[1],"\n" unless $a[2]=~/^CUST/;
}
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 12:54 PM
07-26-2004 12:54 PM
Re: Perl script to replace awk
I dont know if I can explain this correctly by here goes.
I am trying to write a perl program that takes a file let say it looks
like this...
xxxx001,00 0 05 21,TELN NOT
xxxx002,00 0 01 30,TELN NOT
xxxx008,00 0 04 15,TELN NOT
xxxx013,00 0 02 30,CUST HAS
xxxx015,00 0 10 22,CUST HAS
I want to also insert a few things to this file...
I want to prompt user to enter in
print "Enter BLD:"; $bld=
print "Enter ROOM:"; $ROOM=
Also I want a areacode fixed to the first column so when all is said
and done, I have part of the script but can not add the areacode to
it???
#!/opt/perl/bin/perl
$acode="204";
print "Enter BLD:"; $bld=
print "Enter ROOM:"; $room=
while(
chomp;
@a=split(",",$_);
print join(",",$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n") ;
How do I add 204 at the beginning of the [1]?
204xxxx001,EAST_BLD,ROOM1,00 0 05 21,TELN NOT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 02:27 PM
07-26-2004 02:27 PM
Re: Perl script to replace awk
print join(",",$acode.$a[0],$bld,$room,$a[1],$a[2],$a[3],"\n");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2004 04:26 PM
07-26-2004 04:26 PM
Re: Perl script to replace awk
Just to give you some other thinking directions:
# cat x.pl
$bld = shift (@ARGV);
$room = shift (@ARGV);
die "Usage: $0