- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh 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
07-25-2003 03:50 AM
07-25-2003 03:50 AM
Does anyone know how to match a pattern within a text-file for specific linenumbers ?
As an example :
/tmp/text :
bla die bla
line 2 is filled
line 3 is filled
555
line 4 is filled
Now I want to catch the all numbers from lines 3 and 4.
so : var=`cat /tmp/text | ?? parse only lines 3 and 4?? | ?? grep [0-9] ??`
Now I know this looks very silly, but I have Perl in my mind and cannot translate it into ksh. So two questions, how do I only parse specific lines, how do I filter out only numbers for those 2 lines.
Any help will be much apreciated.
Regs David
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 03:56 AM
07-25-2003 03:56 AM
Re: ksh script
Regards,
Bernhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:01 AM
07-25-2003 04:01 AM
Re: ksh script
cat file | awk ' /line 3/,/line4/ '
Quick and dirty ?
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:05 AM
07-25-2003 04:05 AM
Re: ksh script
The awk option only works if you know what is on line 3 and 4, as this is your goal it doesn't help.
Thanks for your try.
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:07 AM
07-25-2003 04:07 AM
Re: ksh script
grep -n -e "[0-9]" /tmp/text | grep -E "^3|^4"
man grep gives you all the info you need
Regards,
Bernhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:10 AM
07-25-2003 04:10 AM
Re: ksh script
I knew I could count on you :)
Regs David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:11 AM
07-25-2003 04:11 AM
Re: ksh script
Second try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:18 AM
07-25-2003 04:18 AM
Re: ksh script
Sorry but i don't understand very well your problem.
Why line4 is 5th line in the file?
The 555 number is the line 4 or is part of the line 3?
If i parse only line 3 and line 4 that you say, i have no matter to catch the 555 number.
Please tell me more accuratelly that you want, perhaps i can help you.
Frank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2003 04:35 AM
07-25-2003 04:35 AM
Re: ksh script
if you only want to pick out the numbers from lines 3 & 4, try this (I'm assuming that all the numbers are integers):
cat text.awk
NR == 3 || NR == 4 {
for (i=1; i<=NF; i++) {
if (int($i) == $i) {
printf("%d ", $i)
}
}
printf("\n")
}
cat /tmp/text | awk -f text.awk
3
555
HTH,
Michael.