- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Awk field seperator
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
тАО01-08-2007 12:01 AM
тАО01-08-2007 12:01 AM
Re: Awk field seperator
Change awk's field separator regex to recognize both . and space.
$ echo hello1 192.168.1.9 | awk -F'[. ]' '{print $2"."$3"."$4}'
192.168.1
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 01:50 AM
тАО01-08-2007 01:50 AM
Re: Awk field seperator
I would have just piped through 2 awk statements - forgot about regex.
IE:
echo hello1 192.168.1.9 | awk '{print $2}' | awk -F. '{print $1"."$2"."$3}'
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 02:20 AM
тАО01-08-2007 02:20 AM
Re: Awk field seperator
Well, it appears that Spex and I agree on the solution :-))
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 04:49 AM
тАО01-08-2007 04:49 AM
SolutionBut you could take the default whitespace field seperator and substitute a period followed by numbers at the end of $2 with nothing:
awk '{sub (/.[0-9]+$/,"",$2); print $2}'
Or you can 'match' the first 3 groups of numbers seperated by a period and print that.
That would allow this to work in free formatted text, not just on 'the second field'.
awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+/); print substr($0,RSTART,RLENGTH)}'
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2007 09:24 PM
тАО01-08-2007 09:24 PM
Re: Awk field seperator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 12:20 PM
тАО01-09-2007 12:20 PM
Re: Awk field seperator
Have you guys tried to double quote the echo string?
By default the -F,FS and OFS are a space character so if you put the echo string in double quote, it preserves the white space and therefore mess it up if add spaces. Try it.
Hein has provided the best solution so far!!!
Open for debate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2007 08:58 PM
тАО01-09-2007 08:58 PM
Re: Awk field seperator
the result of
echo a b | prog
echo 'a b' | prog
echo "a b" | prog
or
prog $(echo a b)
...
will be the same. In the view of the 'echo' command, it's different - in the first case it sees two parameters, in the other one parameter. But the result is the same: 'echo' will send the two parameters to its output, seperated by a space - which is exactly the same in case 2 or 3, where the space is taken from the original input of the single parameter.
Different will be a scenario like this:
echo a
echo 'a
Only in the first case the result would NOT contain a TAB, but a space!
mfG Peter
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2007 01:58 PM
тАО01-10-2007 01:58 PM
Re: Awk field seperator
I would like to get only the first line from the output? (whatever the output might be).
awk '/'hell'/ && !/awk/ {print
$3}' /tmp/target.txt
HH
HH
HH
HH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2007 02:19 PM
тАО01-10-2007 02:19 PM
Re: Awk field seperator
awk '/'hell'/ && !/awk/ {print $2}' /tmp/target.txt |head -1
-denver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2007 02:32 PM
тАО01-10-2007 02:32 PM
Re: Awk field seperator
awk 'NR>1{exit}/'hell'/ && !/awk/ {print $3}' /tmp/target.txt
-denver