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-19-2005 03:03 PM
тАО01-19-2005 03:03 PM
Hello All,
The following awk command prints $1 and $2 variable without space. How can I include the space between two variables.
# echo "This is awk command" | awk 'BEGIN { print "BEGIN" } {print $1$2 ; print $3} END { print $4}'
BEGIN
Thisis
awk
command
Expected Output:
# echo "This is awk command" | awk 'BEGIN { print "BEGIN" } {print $1$2 ; print $3} END { print $4}'
BEGIN
This is
awk
command
Can someone solve my problem??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2005 06:48 PM
тАО01-19-2005 06:48 PM
Re: Reg: awk
print $1$2
with
printf ("%s %s", $1, $2);
Pretty much like C-language printf.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2005 08:23 PM
тАО01-19-2005 08:23 PM
Re: Reg: awk
for your example:
echo "This is awk command" | awk '{printf "BEGIN\n%s %s\n%s\n%s\n", $1,$2,$3,$4}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2005 02:27 AM
тАО01-20-2005 02:27 AM
Re: Reg: awk
echo "This is awk command" | awk 'BEGIN { print "BEGIN" } {space=" " ; print $1 space $2 ; print $3} END { print $4}'
It is not very elegant but works and does not add extra functionality
Frank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2005 11:42 AM
тАО01-20-2005 11:42 AM
SolutionString concatenation when using print is quite interesting in 'awk'.
Whilst using 'print $1 $2;' works, it squishes things together. This is the same as if you use 'print $1.$2;'.
There have been a number of solutions above, but if you are wanting to only include one space, awk allows you to do this with a single comma ('print $1, $2;').
This should work on both GNU awk, as well as commercial unix awk's.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2005 07:59 PM
тАО01-20-2005 07:59 PM
Re: Reg: awk
Would you need 2 spaces between $1 and $2 then one between $2 and $3, this also works:
...{print $1" "$2,$3}...
Have fun.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-20-2005 08:05 PM
тАО01-20-2005 08:05 PM
Re: Reg: awk
Please note that the forum form removes multiple spaces in the strings; in the previous article there should be 2 spaces between the quotes: ..."\ \ "...
Regards.