- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Extract fields from text file.
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
тАО05-02-2007 12:27 AM
тАО05-02-2007 12:27 AM
I have df -k output text
Can any body help me in extracting last 2 column fields(Space Separator) from below text irrespective of no. of coloumns.
mpfs 38G 0K 38G 0% /dev/vx/rdmp
swap 38G 356M 38G 1% /tmp
/dev/vx/dsk/bootdg/opt
32G 15G 17G 48% /opt
/dev/vx/dsk/tempbackup_DG/tempvol
200G 8.6G 179G 5% /tempbackup
/dev/vx/dsk/dbaarch_DG/dbaarch_data_Vol6
98G 28G 69G 29% /opt/oraclea/arch
/dev/vx/dsk/dbabckp_DG/dbabckp_data_Vol5
100G 25G 75G 25% /opt/oraclea/backup
/dev/vx/dsk/dba_DG/dba_data_Vol2
50G 48G 1.6G 97% /opt/oraclea/mnt2
Any tips.
Thanks & Regards,
Rajesh SB
Solved! Go to Solution.
- Tags:
- bdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:30 AM
тАО05-02-2007 12:30 AM
Re: Extract fields from text file.
try this
df -k > dfk.txt
awk ├в F├в ├в ├в { print $5, $6 }├в dfk.txt
regards
pg
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:34 AM
тАО05-02-2007 12:34 AM
Re: Extract fields from text file.
This seems to work overhere:
# cat file.txt | awk '{FROM=(NF-2);print $FROM,$(FROM+1),$NF}'
--> returns 3 last fields.
Cheers,
Wout
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:37 AM
тАО05-02-2007 12:37 AM
Re: Extract fields from text file.
Some of the lines are having 6 columns and some are with 5 columns.
I am particularly looking for mount-point and percentage columns.
You command won't work.
Any other tips.
Regards,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:40 AM
тАО05-02-2007 12:40 AM
Re: Extract fields from text file.
# awk '{print $NF,$(NF-1)}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:41 AM
тАО05-02-2007 12:41 AM
SolutionI would add a check to send output only when there are more than 2 columns - this will deal correctly with the bdf output for long device names:
bdf -l | awk 'NF>2 {print $(NF-1),$NF}'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:52 AM
тАО05-02-2007 12:52 AM
Re: Extract fields from text file.
You command is working fine.
Highly appreciate your timely response.
Case-1 Not Worked
cat df-k.op| awk '{FROM=(NF-2);print $FROM,$(FROM+1),$NF}'
awk: The field -1 must be in the range 0 to 199.
The input line number is 2.
The source line number is 1.
Case-2 Not worked:
cat df-k.op|grep -v Filesystem| awk '{FROM=(NF-2);print $FROM,$(FROM+1),$NF}'
Thanks to you all for quick response again
Thanks & Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 12:56 AM
тАО05-02-2007 12:56 AM
Re: Extract fields from text file.
Avoid the extra 'cat' process just to read a file. Instead of :
# cat myfile | awk '...'
...simply do:
# awk '...' myfile
Regards!
...JRF...
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 01:01 AM
тАО05-02-2007 01:01 AM
Re: Extract fields from text file.
(you know how it goes: make a sample file, cat it to check, use command history and start piping..)
Also, sorry for confusing the numbers two and three. That should not happen too often or I'm going to get myself in trouble one day :-)
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2007 01:11 AM
тАО05-02-2007 01:11 AM
Re: Extract fields from text file.
It is good to avoid unnecessary extra command usage.
Learning is never ending process!
Cheers,
Rajesh