- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script
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
09-26-2002 06:43 AM
09-26-2002 06:43 AM
I have a text file which has a BEGIN and END for each entry in it. I am trying to extract a field (enclosed in +++) from each entry and for that corresponding entry i am trying to extract another two lines (enclosed in ---) and pass it to another command. Could someone please tell me how I can do this. (Note: the +++ and --- do not exist in the original file it is only for identifying the field)
Rgds,
Gen
Please find the text file below.
???BEGIN +++ 702076283 +++???
??? AA=123A,VV=PQR7,SS=CAT067B ???
??? --- ALARM 299 O1/SW_DEV "CBC71C0021A07E0"A 020925 1115???
???DIGITAL PATH QUALITY SUPERVISION---???
???BES???
???WIP WIPPART SESL2 QSV SECTION DATE TIME???
???RBLT18 1 2 020925 111500???
???END ???
???BEGIN +++702086280 +++???
??? NW=TSS,NE=TRS7,EQ=TAX067A ???
??? --- ALARM 297 A2/SW_DEV "BSC71C0021A07E0"A 020925 0741???
???RADIO X-CEIVER ADMINISTRATION---???
???MANAGED OBJECT FAULT???
???MO RSITE ALARM SLOGAN???
???RXOTS-6-0-5 TAX067A TS SYNC FAULT???
???END???
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 06:50 AM
09-26-2002 06:50 AM
Re: Script
Crudely:
# awk '/BEGIN/,/END/ {print $0}' filein | awk '/---/,/---/ {print $0}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:02 AM
09-26-2002 07:02 AM
Re: Script
Here is an awk script to search for BEGIN and save the number following it. It then looks for ALARM and prints the saved number and the line.
awk -e '/^BEGIN/{sav=$2};/^ALARM/{print sav,$0}' yourfile
hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:05 AM
09-26-2002 07:05 AM
Re: Script
I could manage to get the first field the one enclosed in +++. But I am having trouble with the second one (the text enclosed in ---) because it is more than one line. The real file does not have +++ and --- on it.
Thank you for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:26 AM
09-26-2002 07:26 AM
Re: Script
:1
/^BEGIN
f (that's an f, then a space ( ) VERY IMPORTANT)
:1
:map x /ctrlVctrlM;li+++ctrlV
then type in x for every "block"
note: ctrlV
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:28 AM
09-26-2002 07:28 AM
Re: Script
As Rod says, it's not clear how to identify the lines you're after. If we assume they're always two lines long, you want them joined together, and they're always the 2nd/3rd lines after the BEGIN line, then:
awk '/BEGIN/{getline;getline;s=$0;getline;print s$0}' file
would be one way of doing it.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:31 AM
09-26-2002 07:31 AM
Solutionawk '
{
if($1=="BEGIN") item1=$3;
if($1=="---") {
item2=substr($0,5);
getline;
item3=$0;
gsub("-","",item3);
}
if($1=="END") print item1,item2,item3;
}' filein
result :
702076283 ALARM 299 O1/SW_DEV "CBC71C0021A07E0"A 020925 1115 DIGITAL PATH QUAL
ITY SUPERVISION
702086280 ALARM 297 A2/SW_DEV "BSC71C0021A07E0"A 020925 0741 RADIO XCEIVER ADM
INISTRATION
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:40 AM
09-26-2002 07:40 AM
Re: Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 07:44 AM
09-26-2002 07:44 AM
Re: Script
DATA=data
ENTRIES=`cat $DATA |grep "^BEGIN" |awk '{print $2}'`
for ENTRY in $ENTRIES
do
echo "ENTRY: $ENTRY"
sed '1,/'$ENTRY'/d' $DATA |head -3|tail -2
done
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 08:10 AM
09-26-2002 08:10 AM
Re: Script
Thanks to all for the help.
Thank you Jean-Luc your solution worked perfect.
Rgds,
Dinesh.