- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Incrementing two lists for variables at the sa...
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
тАО02-13-2008 08:42 AM
тАО02-13-2008 08:42 AM
I need help with finding a solution to an ongoing challenge for me. I need to find a way to increment lists for variables at the same time. Here is an example of my current challenge:
I need to change a whole slew of users accounts to a new login ID.
I have two lists. One list has the current user ID's, and the other list has the new user ID's. How can I script this, so that both lists are read in order, and in sync? In other words, I want the first line of the first list to correspond with the 1st line of the 2nd list, and so on. How would I do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 08:48 AM
тАО02-13-2008 08:48 AM
Re: Incrementing two lists for variables at the same time.
please post the format of the files.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 08:55 AM
тАО02-13-2008 08:55 AM
Solution# paste file1 file2 > file3
Then when you script your user modification routine do something like:
while read OLDUID NEWUID
do
...do stuff here...
done < file3
- Tags:
- paste
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 09:00 AM
тАО02-13-2008 09:00 AM
Re: Incrementing two lists for variables at the same time.
user1
user2
user3
user4
user5
user6
user7
user8
user9
user10
...and so on...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 09:12 AM
тАО02-13-2008 09:12 AM
Re: Incrementing two lists for variables at the same time.
file1:
01
02
03
04
05
file2:
06
07
08
09
010
paste file1 file2 >file3
file3
01 06
02 07
03 08
04 09
05 010
hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 09:17 AM
тАО02-13-2008 09:17 AM
Re: Incrementing two lists for variables at the same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 09:58 AM
тАО02-13-2008 09:58 AM
Re: Incrementing two lists for variables at the same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 10:10 AM
тАО02-13-2008 10:10 AM
Re: Incrementing two lists for variables at the same time.
When I do this:
while read OLDUID NEWUID
do
echo $OLDUID $NEWUID
done < users.txt
I get this:
user1-1 user2-1
user1-2 user2-2
user1-3 user2-3
user1-4 user2-4
user1-5 user2-5
user1-6 user2-6
It is working! Now to modify it to my needs!! Thx all!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2008 02:30 PM
тАО02-13-2008 02:30 PM
Re: Incrementing two lists for variables at the same time.
using more exotic I/O redirection, providing
a look (open, read, ...) closer to that of a
regular programming language (like DCL, for
example):
dy # cat ./nm.dat
aaa
bbb
ccc
dy # cat ./nr.dat
111
222
333
dy # cat ./rdr.sh
#!/bin/sh
exec 3<./nm.dat
exec 4<./nr.dat
while read nm <&3 ; do
read nr <&4
echo "nm: >${nm}<, nr: >${nr}<."
done
dy # ./rdr.sh
nm: >aaa<, nr: >111<.
nm: >bbb<, nr: >222<.
nm: >ccc<, nr: >333<.
It's also possible to add some error handling
to cope with file pairs with different line
counts, and it may be easier to do this well
if you keep the files' data separate. (After
"paste" smooshes them together, it may not be
obvious which one has the problem.)
Reverse the "<" characters, and it's possible
to write to more than one file at a time
(more than only stdout), too, just as this
script shows how to read from more than one
file at a time (more than only stdin).
- Tags:
- redirect