- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk problem
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
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
11-13-2006 10:03 PM
11-13-2006 10:03 PM
awk problem
File.txt
/Home/temp/user /Thisismyhome/
/Home/temp/newuser /Thisismyhome/
/Home/temp/bob /Thisismyhome and something/
When I print $1,$2 I get
/Home/temp/user /Thisismyhome/
/Home/temp/newuser /Thisismyhome/
/Home/temp/bob /Thisismyhome
But I need to include the “and something/” from the last line i.e. $3 and $4
So I want to print something like $1, $2* (the star being to the end of the line)
Anybody got any ideas?
All help appreciated
Declan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2006 10:14 PM
11-13-2006 10:14 PM
Re: awk problem
until you get your awk solution:
#!/usr/bin/sh
while read dat1 dat2
do
echo $dat1
echo $dat2
done < datafile
dat1 = Data to first space
dat2 = All other data to end of line
If you add dat3 to the read line:
dat1 = Data to first space
dat2 = Data from end of dat1 to second space
dat3 = All other data to end of line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2006 11:32 PM
11-13-2006 11:32 PM
Re: awk problem
How about:
# awk -F' /' '{print $1,$2}' File.txt
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2006 11:50 PM
11-13-2006 11:50 PM
Re: awk problem
Remember, you can also set NF.
So you can do: awk '{NF=4; print}' x.txt
Just keep on printing?
awk '{print $1,$2,$3,$4}
Count, using printf to avoid new-line?
awk '{for (i=1; i
So many ways, the best one depends on the exact problem to solve.
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2006 12:04 AM
11-14-2006 12:04 AM
Re: awk problem
and my awk solution:
awk '{print $1,$2=substr($0,length($1)+1)}' datafile
Which prints the first field and then works out the string to print for field to by taking the whole line ($0) and moving the start point to print just past the length of the first field. The end point is the end of the line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2006 12:17 AM
11-14-2006 12:17 AM
Re: awk problem
Thanks again
Declan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2006 12:29 AM
11-14-2006 12:29 AM
Re: awk problem
awk '{print$2=substr($0,length($1)+1)}' datafile.txt
Thanks again to everyone
Regards
Declan