- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script to get a piece of data from a file.
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
02-06-2006 06:49 PM
02-06-2006 06:49 PM
Shell script to get a piece of data from a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 06:51 PM
02-06-2006 06:51 PM
Re: Shell script to get a piece of data from a file.
Use grep or perl or sed or awk to get it done. Post to help you out.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 07:04 PM
02-06-2006 07:04 PM
Re: Shell script to get a piece of data from a file.
You can simply use "grep" to do that.
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 07:43 PM
02-06-2006 07:43 PM
Re: Shell script to get a piece of data from a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 07:51 PM
02-06-2006 07:51 PM
Re: Shell script to get a piece of data from a file.
how about:
#!/usr/bin/sh
x="
y=`echo $x | cut -d'>' -f2`
echo `echo $y | cut -d'<' -f1`
First cut eliminates everything before the ">"
Second cut elimintates everything following the "<"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2006 07:58 PM
02-06-2006 07:58 PM
Re: Shell script to get a piece of data from a file.
#!/usr/bin/ksh
# user the shell of choice
> outputfile
string1="hello"
string2="goodbye"
string3="whatever"
grep $string1 inputfile >> outputfile
grep $string2 inputfile >> outputfile
grep $string3 inputfile >> outputfile
You could use Korn shell array processing to make it prettier.
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
02-06-2006 08:30 PM
02-06-2006 08:30 PM
Re: Shell script to get a piece of data from a file.
let'say that xmlfile is the file containing the string you want to extract. You can use something like:
awk '
/^
gsub(/<\/*ABCDE>/, "")
}' < xmlfile
the above command will:
1. extract ALL lines with the given tag (
2. the tag part will be deleted and only the string inside the tag will be printed
3. the lines must contain ONLY the tag to be extracted, meaning that a line like
will NOT be extracted. This is for the use of character ^ and $ in the regexp pattern used to address the awk command
If you need to extract the given part of tag from all lines you need something more complex like:
awk '
/
gsub(/^.*
gsub(/<\/ABCDE>.*$/, "")
}' < xmlfile
In general see awk man to manage text files inside a script: awk is really a powerfull and efficient tool to work on text file.
You can do almost everything with it. :-)
hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2006 04:46 PM
02-08-2006 04:46 PM
Re: Shell script to get a piece of data from a file.
Thanks to all for help.