- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script ideas??
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
04-15-2004 03:01 AM
04-15-2004 03:01 AM
i.e. INPUT returns OUTPUT
XXXXX[A]XXXXX returns A
XYXYX[ABC]XYX returns ABC
ZXCZX[A][B]ZC returns AB
etc...
Does anyone have any ideas please....
Cheers
Russ
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:14 AM
04-15-2004 03:14 AM
Re: Script ideas??
awk using [ and or ] to strip the data into a variable
var1=$(awk[ 'print $1')
This is just a course of action, the code doesn't work.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:19 AM
04-15-2004 03:19 AM
Re: Script ideas??
A
ABC
AB
#
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:19 AM
04-15-2004 03:19 AM
Re: Script ideas??
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:24 AM
04-15-2004 03:24 AM
Re: Script ideas??
and it also uses cat where absolutely not neccecary. Useless waste of process space. Use input redirection instead:
NOT # cat file | process
BUT # process < file
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:29 AM
04-15-2004 03:29 AM
Re: Script ideas??
{usestring=$0;printstring="";
for (idx1=1;idx1
check1=index(usestring,"[");
check2=index(usestring,"]");
if (check1>0)
{use2=substr(usestring,check1+1,check2-check1-1);
printstring=printstring use2; idx1=check2+1;
}
else
{idx1=length($0);}
}
print printstring;
}
Then run:
awk -f s.awk < input > output
I'm sure I could stream line it, but it will work as it is now.
Best regards,
Kent M. Ostby
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 03:33 AM
04-15-2004 03:33 AM
Re: Script ideas??
I am learing perl from gurus like you.
And yes car=t was required. I did not give that much thought to it. Was very fast.
anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 04:05 AM
04-15-2004 04:05 AM
Solutionawk '{
i2=index($0,"]");
str=$0;
while(i2 > 0) {
i1=index(str,"[");
printf("%s",substr(str,i1 + 1,i2 - i1 -1));
str=substr(str,i2 + 1, length(str));
i2=index(str,"]");
}
printf("\n");
} '
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 07:30 PM
04-15-2004 07:30 PM
Re: Script ideas??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 07:42 PM
04-15-2004 07:42 PM
Re: Script ideas??
Do you need explaining of any part?
In the original part you did not state what script language you wanted.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 09:02 PM
04-15-2004 09:02 PM
Re: Script ideas??
But if are sure the brackets are always matched, you could also do it this way:
awk '/\[/ { sub("^[^\[]*\[","");
sub("\][^\[]*$","");
sub("\][^\[]*\[","");
}'
Same could be done with sed and some replacements using sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 09:07 PM
04-15-2004 09:07 PM
Re: Script ideas??
But I still think Procura's solution is better and on large files faster.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 09:08 PM
04-15-2004 09:08 PM
Re: Script ideas??
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is more to it... Jean-Luc's code will fail if you have lines containing closing square brackets, but without opening brackets, you will get those lines too.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code is based on the sample from the poster.
Merijn,
No offence, I don't think my code is unmaintainable. Certainly, it takes more than one line, and if don't speak perl, that's where you cannot maintain it , would you agree ?
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2004 09:26 PM
04-15-2004 09:26 PM
Re: Script ideas??
IMHO my perl solution is sooooo darn simple that it just is the best solution. No offence to anyone, and I know I sometimes post rather obfuscated solutions, but this one is so simple that I cannot understand why someone would choose any other solution.
There is a right tool for every problem, and I'm not stating that tool is Perl all the time, but here it outperforms any other in simplicity and shortness
Enjoy, Have FUN! H.Merijn