HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Trying to extract data from multiple files
Operating System - HP-UX
1833541
Members
2723
Online
110061
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
01-05-2004 10:03 AM
01-05-2004 10:03 AM
I'm trying to write a script that will extract several lines of information from multiple ascii files and then parse it to a single file.
I'm trying to get the FILENAME of the file and 1 or more lines that start off with "#Description:". The "Description" lines are not always on the same line number. I want the output file to read something like:
FILENAME DESCRIPTION
filename1 does whatever
filename2 checks whatever
also does whatever
Thanks in advance!
Ken
I'm trying to get the FILENAME of the file and 1 or more lines that start off with "#Description:". The "Description" lines are not always on the same line number. I want the output file to read something like:
FILENAME DESCRIPTION
filename1 does whatever
filename2 checks whatever
also does whatever
Thanks in advance!
Ken
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 10:11 AM
01-05-2004 10:11 AM
Re: Trying to extract data from multiple files
A simple "grep"-
grep "^#Description" yourfiles*
HTH
-- Rod Hills
grep "^#Description" yourfiles*
HTH
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2004 10:27 AM
01-05-2004 10:27 AM
Solution
Here's one method that takes advantage of the shell's read command.
read V1 V2 would read
#DESCRIPTION This is a test
and stuff "#DESCRIPTION" into V1 and everything else (because V2 is the last variable) into V2.
#!/usr/bin/sh
FILES="myfile1 myfile2 myfile3"
echo "FILENAME\tDESCRIPTION"
echo
for FILE in ${FILES}
do
grep -E -q "^#DESCRIPTION" ${FILE}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then #found
grep -E "^#DESCRIPTION" ${FILE} | while read V1 V2
do
echo "${FILE}\t${V2}"
done
fi
done
Note that we intentionally ignore ${V1} because it contains the known string "#DESCRIPTION".
read V1 V2 would read
#DESCRIPTION This is a test
and stuff "#DESCRIPTION" into V1 and everything else (because V2 is the last variable) into V2.
#!/usr/bin/sh
FILES="myfile1 myfile2 myfile3"
echo "FILENAME\tDESCRIPTION"
echo
for FILE in ${FILES}
do
grep -E -q "^#DESCRIPTION" ${FILE}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then #found
grep -E "^#DESCRIPTION" ${FILE} | while read V1 V2
do
echo "${FILE}\t${V2}"
done
fi
done
Note that we intentionally ignore ${V1} because it contains the known string "#DESCRIPTION".
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2004 02:09 AM
01-06-2004 02:09 AM
Re: Trying to extract data from multiple files
Thanks for the help.
Clay's script is exactly what I was trying to do.
Clay's script is exactly what I was trying to do.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP