- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed -> awk buffers ...
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
02-24-2005 12:38 AM
02-24-2005 12:38 AM
sed "s/^\([^:]*\):\([^:]*\)/\2:\1/" /tmp/somefile.txt
This sed snippet takes a colon delimited file and switches the first and second field. How do you do the same thing in awk?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:42 AM
02-24-2005 12:42 AM
Re: sed -> awk buffers ...
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:46 AM
02-24-2005 12:46 AM
Re: sed -> awk buffers ...
How about sub-field matches? I'm really interested in the buffering \( \) in sed ... how do you do the same thing in awk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:49 AM
02-24-2005 12:49 AM
Re: sed -> awk buffers ...
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:50 AM
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:50 AM
02-24-2005 12:50 AM
Re: sed -> awk buffers ...
regards,
Thierry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 01:01 AM
02-24-2005 01:01 AM
Re: sed -> awk buffers ...
cat /tmp/somefile.txt | cut -f 1,2 -d : | awk '{print $2," ",$1 }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 01:07 AM
02-24-2005 01:07 AM
Re: sed -> awk buffers ...
like SED:
perl -pe 's/(.*):(.*):/$2:$1:/' x
Split words in an array, swap, join and have printed:
perl -pe '@words=split(":"); $x=$words[0];$words[0]=$words[1];$words[1]=$x; $_=join(":",@words)' x
Split, join in new order, and print.
The final @words is in scalar context and is the number of elements of words.
perl -pe '@words=split(":"); $_=join(":",@words[1,0,2..@words])' x
grins,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 01:13 AM
02-24-2005 01:13 AM
Re: sed -> awk buffers ...
awk -F: '{printf "%s:%s",$2,$1;
for (i=3;i<=NF;i++)
printf ":%s",$i
printf "\n";
}' < /tmp/somefile.txt
You could also use split on $0 with a ":" seperator and swap the first two array entries, for instance. But the resulting could would be bigger as the above one, since I don't know of a join function in awk, like in perl.
Good luck,
Elmar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 01:19 AM
02-24-2005 01:19 AM
Re: sed -> awk buffers ...
My perl example for the SED look alike is wrong.
I forgot about the greedy-ness of the .* match. So you can not say 'anything' because that may include colons. You have to say 'any number of non-colon chars'
perl -pe 's/([^:]*):([^:]*):/$2:$1:/' x
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2005 11:36 PM
02-27-2005 11:36 PM
Re: sed -> awk buffers ...
Thanks, all.