- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- vi question
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
06-09-2007 06:51 PM
06-09-2007 06:51 PM
vi question
I have minimaly used sed and awk stuffs.
Now i have a file which has a user data seperated with :
In which i have to replace a coulmn E(has user dept) with new information. some users have multiple entries in the file . How can i script to replace a particular column with new info (i have a file with the new info)
Thanks in advance
- Tags:
- vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2007 07:57 PM - edited 09-25-2011 08:24 PM
06-09-2007 07:57 PM - edited 09-25-2011 08:24 PM
Re: awk question
What is your "key" for info you want to take from that other file? You may want to look at join(1), after you sort the two files on their key.
If the number of lines in your two files is not too big, you could read your new file with awk and make an associative array then read in your data file and just replace that column E with data in the array that matches.
If your separator is a ":", then you want awk -F:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2007 09:43 PM
06-09-2007 09:43 PM
Re: vi question
Looks like you want to modify /etc/passwd.
A quick one came to my mind is here. Below you are excluding the column 5 (column E) from the original file and redirect the result to file1
#awk -F: 'BEGIN { OFS=":" } { $5 = ""; print }' /etc/passwd > file1
Now you are merging the file1 with the newinfo file which contains the new info and redirect that result to a file called result
#paste -d: file1 newinfo > result
Finally you are extracting
#awk -F: 'BEGIN { OFS=":" } {print $1, $2, $3, $4, $8, $6, $7}' result > final
#diff /etc/passwd final
Regards,
Rasheed Tamton.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2007 01:41 AM
06-10-2007 01:41 AM