- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- parsing text by scripting
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-25-2001 09:03 AM
09-25-2001 09:03 AM
the last record that has the id no. The
first field within double quotes is always id no.
The input text file is below and the output I want to see is in the end. Can't figure it out.?
Help please.
INPUT FILE:
==========================
{"123", "sam", "Test"}
{"123", "sami", "Test Only"}
{"123", "samuel", "This is the record I want"}
{"345", "sharo19", "VICC eassocr"}
{"678", "pat", "Test2"}
{"678", "patrick1", "Real Test now"}
{"321", "sharo19", "VICC eassocr"}
===============================
OUTPUT NEEDED FROM THE ABOVE INPUT FILE is:
===========================================
{"123", "samuel", "This is the record I want"}
{"345", "sharo19", "VICC eassocr"}
{"678", "patrick1", "Real Test now"}
{"321", "sharo19", "VICC eassocr"}
===========================================
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 09:47 AM
09-25-2001 09:47 AM
Re: parsing text by scripting
Try this:
#!/usr/bin/sh
typeset MYFILE=$1
awk -F, 'BEGIN {TOG=0;D=$1;S=$0}
{if (TOG==1 && D!=$1)
{print S} TOG=1;D=$1;S=$0}
END {print S}' $MYFILE
exit 0
#.end.
Pass your input file as an arguement to the script above and you will get the desired output.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 10:32 AM
09-25-2001 10:32 AM
SolutionOops. The 'awk' BEGIN rule (although harmless) is superfluous. Actually no I/O has occured at that point and I should have dropped it, simplfying to:
#!/usr/bin/sh
typeset MYFILE=$1
awk -F, '{if (TOG==1 && D!=$1) {print S} TOG=1;D=$1;S=$0}
END {print S}' $MYFILE
exit 0
#.end.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 10:44 AM
09-25-2001 10:44 AM
Re: parsing text by scripting
Here's another way to do it,
/Begin/
#!/usr/bin/sh
if [[ $# < 1 ]]
then
echo "Usage: $0 filename"
exit 1
fi
cat $1 |sort -n |cut -d \" -f 2 |uniq |while read id
do
grep "$id" "$inputfile" |tail -1
done
/End/
To run it
script.sh filename
-HTH
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 10:46 AM
09-25-2001 10:46 AM
Re: parsing text by scripting
This should definitely work
/Begin/
#!/usr/bin/sh
if [[ $# < 1 ]]
then
echo "Usage: $0 filename"
exit 1
fi
cat $1 |sort -n |cut -d \" -f 2 |uniq |while read id
do
grep "$id" "$1" |tail -1
done
/End/
-Regards
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 10:48 AM
09-25-2001 10:48 AM
Re: parsing text by scripting
awk '{
split($0,array,"\"");
id=array[2];
bigA[id]=$0;
} END {
for ( i in bigA )
print bigA[i];
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2001 11:48 AM
09-25-2001 11:48 AM
Re: parsing text by scripting
All of your script did what I asked for .