- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk - printing all fields other than first field i...
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
тАО03-06-2001 11:14 AM
тАО03-06-2001 11:14 AM
How do you print all fields other than the first field in a variable length record using awk utility ? The field delimiter is space.
Any help is appreciated
Thanks in advance
Bala
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:04 PM
тАО03-06-2001 12:04 PM
Re: awk - printing all fields other than first field in a variable length record
awk '{ print $0 }'
For example: awk '{ print $0 }' < /tmp/test
will print the contents of the file /tmp/test no matter what the line length.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:31 PM
тАО03-06-2001 12:31 PM
Re: awk - printing all fields other than first field in a variable length record
I donot want to print the first field. $0 will print the full record. I want to print from second field to last field. Here the last field is not fixed since it is a variable length record.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:42 PM
тАО03-06-2001 12:42 PM
Re: awk - printing all fields other than first field in a variable length record
Try this:
# echo "a b c \nd e f"|awk '{array [NF]=$0;for (i=2;i<=NF;i++) printf("%s ",$i);printf("\n")}'
This will echo two lines:
b c
e f
...which represent the second through last fields of the two records input by example.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:45 PM
тАО03-06-2001 12:45 PM
Re: awk - printing all fields other than first field in a variable length record
You can use $1 $2 ... $n to print the individual fields of the current record.
...Madhu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:46 PM
тАО03-06-2001 12:46 PM
Re: awk - printing all fields other than first field in a variable length record
# cat /etc/passwd|while read LINE;do
> echo $LINE|awk -F":" '{split($0,a)}
> {for(i=2;i<=NF;i++) print a[i]}'
> done
This prints out everything except the first field of the /etc/passwd file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:53 PM
тАО03-06-2001 12:53 PM
Solutioncat test | awk '{sub($1,"");sub(" ","");print}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:53 PM
тАО03-06-2001 12:53 PM
Re: awk - printing all fields other than first field in a variable length record
cat test | awk '{sub($1,"");sub(" ","");print}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 12:55 PM
тАО03-06-2001 12:55 PM
Re: awk - printing all fields other than first field in a variable length record
Here is some sample output from my last post:
The test file first:
# cat test
this is line 1
this is another line in the file
this is line 3
this is yet another line in the test file
line 4
And now running the command:
# cat test | awk '{sub($1,"");sub(" ","");print}'
is line 1
is another line in the file
is line 3
is yet another line in the test file
4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-06-2001 01:10 PM
тАО03-06-2001 01:10 PM
Re: awk - printing all fields other than first field in a variable length record
#!/bin/sh
cat /etc/passwd | awk -F: '
{for (i=2; i <= NF ; i++) print "Field",i,": ",$i}'
If I've retyped this right, ...
/rcw