- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script for capturing only few values from the ...
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
Discussions
Discussions
Forums
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
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
тАО03-10-2009 01:26 PM
тАО03-10-2009 01:26 PM
I understand that this is not a scripting forum, but I believe this should be very easy for you experts.
First line of my file contains some data like this "abcdefg.xx 123 xx.yy.zz.11 There is some variable length text here 03/10/09"
Note that:
1) where I see "123" it will never be more than 4 characters. But it can be of zero characters too. Meaning it does not exist.
2) Line will always end with a date, so it will contain a character "/" in it.
3) What I am want to extract is the value "xx.yy.zz.11 There is some variable length text here". This could be of any length, any number of words, any characters.
Do any of you have a script/command to make this happen? Lets assume that filename is workfile.txt.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2009 02:29 PM
тАО03-10-2009 02:29 PM
Solution# X="abcdefg.xx 123 xx.yy.zz.11 There is some variable length text here 03/10/09"
# Y="abcdefg.xx xx.yy.zz.11 There is some variable length text here 03/10/09"
# echo ${X}|perl -nle 'm{.+?\s+(\d+\s+)*(.+)} and print $2'
xx.yy.zz.11 There is some variable length text here 03/10/09
...and:
# echo ${Y}|perl -nle 'm{.+?\s+(\d+\s+)*(.+)} and print $2'
xx.yy.zz.11 There is some variable length text here 03/10/09
...which distinguishes rule-1.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2009 03:14 PM
тАО03-10-2009 03:14 PM
Re: Script for capturing only few values from the first line of a file
perl -ne 'print "$1\n" if /^[A-Za-z]+\.[0-9][0-9].* ([0-9][0-9]\.[0-9][0-9]\.[0-
9][0-9]\.11) .+ [0-1]?[0-9]\/[0-3]?[0-9]\/[0-9][0-9]$/' workfile.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-10-2009 04:22 PM
тАО03-10-2009 04:22 PM
Re: Script for capturing only few values from the first line of a file
You could use awk:
awk '
{
if (length($2) > 4) # optional field
start = 2
else
start = 3 # skip optional field
printf "%s", $start
for (i = start+1; i < NF; ++i)
printf " %s", $i
print ""
exit
}' workfile.txt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2009 02:50 AM
тАО03-11-2009 02:50 AM
Re: Script for capturing only few values from the first line of a file
Try this also :
head -1 workfile.txt | sed 's/^.*123 \(.*$\)/\1/'
If "123" is not present in the line, the commands will give the entire line
If you need nothing when "123" is not present, insert before sed a grep command so you will have this :
head -1 workfile.txt | grep 123 | sed 's/^.*123 \(.*$\)/\1/'
Good luck,
Roland
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2009 03:36 AM
тАО03-11-2009 03:36 AM
Re: Script for capturing only few values from the first line of a file
Assuming a file named 'file' contains:
Please wait...checking for disk quotas
(c)Copyright 1983-2000 Hewlett-Packard Co., All Rights Reserved.
$ line
Please
$ echo $second
wait...checking for disk quotas
$ line
Please
$ echo $second
wait...checking
$ echo $rest_of_line
for disk quotas
$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2009 12:09 PM
тАО03-11-2009 12:09 PM
Re: Script for capturing only few values from the first line of a file
# cat foo
abcdefg.xx 123 xx.yy.zz.11 There is some variable length text here 03/10/09
abcdefg.xx 13 xx.yy.zz.11 There is some variable length text here 03/10/09
abcdefg.xx xx.yy.zz.11 There is some variable length text here 03/10/09
abcdefg.xx 3 xx.yy.zz.11 There is some variable length text here 03/10/09
# cut -d\ -f2 foo
123
13
3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2009 12:15 PM
тАО03-11-2009 12:15 PM