Sponsored Content
Top Forums Shell Programming and Scripting Editing one word in a file on 50nodes simultaniously Post 302089319 by BOFH on Monday 18th of September 2006 02:40:39 PM
Old 09-18-2006
Hmm, you'd basically use sed to change the commands, write to a temporary file and then copy the temporary file back over the first file. Lots of problems with that though. Permissions and owerships being top on my list. Error checking to make sure the temporary file is complete. In the case of the /etc/passwd file, blocks in place to keep someone from changing it while you're doing it.

But you said you have an app on each node so you just need the command. Easy enough:

Code:
sed -e "s/^bin:/binuser:/" /etc/passwd

You'll have to write the output to that temporary file I mentioned or it'll just display to the tty/console.

Carl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

2. Shell Programming and Scripting

find a word in a file, and change a word beneath it ??

Hi all, I have a file with lines written somewhat like this. aaaa ccc aa linux browse = no xssxw cdcedc dcsdcd csdw police dwed dwd browse = no cdecec (2 Replies)
Discussion started by: vikas027
2 Replies

3. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

4. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

5. Shell Programming and Scripting

Help with file editing while keeping file format intact

Hi, I am having a file which is fix length and comma seperated. And I want to replace values for one column. I am reading file line by line in variable $LINE and then replacing the string. Problem is after changing value and writing new file temp5.txt, formating of original file is getting... (8 Replies)
Discussion started by: Mruda
8 Replies

6. Shell Programming and Scripting

editing line in text file adding number to value in file

I have a text file that has data like: Data "12345#22" Fred ID 12345 Age 45 Wilma Dino Data "123#22" Tarzan ID 123 Age 33 Jane I need to figure out a way of adding 1,000,000 to the specific lines (always same format) in the file, so it becomes: Data "1012345#22" Fred ID... (16 Replies)
Discussion started by: say170
16 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

9. Shell Programming and Scripting

Convert vi editing to text editing

Dear Guru's I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response. Srini (6 Replies)
Discussion started by: thummi9090
6 Replies

10. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies
PW_UTIL(3)						   BSD Library Functions Manual 						PW_UTIL(3)

NAME
pw_copy, pw_dup, pw_edit, pw_equal, pw_fini, pw_init, pw_make, pw_make_v7, pw_mkdb, pw_lock, pw_scan, pw_tempname, pw_tmp -- functions for passwd file handling LIBRARY
System Utilities Library (libutil, -lutil) SYNOPSIS
#include <pwd.h> #include <libutil.h> int pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *oldpw); struct passwd * pw_dup(const struct passwd *pw); int pw_edit(int nosetuid); int pw_equal(const struct passwd *pw1, const struct passwd *pw2); void pw_fini(void); int pw_init(const char *dir, const, char, *master"); char * pw_make(const struct passwd *pw); char * pw_make_v7(const struct passwd *pw); int pw_mkdb(const char *user); int pw_lock(void); struct passwd * pw_scan(const char *line, int flags); const char * pw_tempname(void); int pw_tmp(int mfd); DESCRIPTION
The pw_copy() function reads a password file from ffd and writes it back out to tfd possibly with modifications: - If pw is NULL and oldpw is not NULL, then the record represented by oldpw will not be copied (corresponding to user deletion). - If pw and oldpw are not NULL then the record corresponding to pw will be replaced by the record corresponding to oldpw. - If pw is set and oldpw is NULL then the record corresponding to pw will be appended (corresponding to user addition). The pw_copy() function returns -1 in case of failure otherwise 0. The pw_dup() function duplicates the struct passwd pointed to by pw and returns a pointer to the copy, or NULL in case of failure. The new struct passwd is allocated with malloc(3), and it is the caller's responsibility to free it with free(3). The pw_edit() function invokes the command specified by the EDITOR environment variable (or /usr/bin/vi if EDITOR is not defined) on a tempo- rary copy of the master password file created by pw_tmp(). If the file was modified, pw_edit() installs it and regenerates the password database. The pw_edit() function returns -1 in case of failure, 0 if the file was not modified, and a non-zero positive number if the file was modified and successfully installed. The pw_equal() function compares two struct passwd and returns 0 if they are equal. The pw_fini() function destroy the temporary file created by pw_tmp() if any, kills any running instance of EDITOR executed by pw_edit() if any, and closes the lock created by pw_lock() if any. The pw_init() initialize the static variable representing the path a password file. dir is the directory where the password file is located. If set to NULL, it will default to /etc. master is the name of the password file. If set to NULL? it will default to master.passwd The pw_make() function creates a properly formatted BSD passwd(5) line from a struct passwd, and returns a pointer to the resulting string. The string is allocated with malloc(3), and it is the caller's responsibility to free it with free(3). The pw_make_v7() function creates a properly formatted UNIX V7 passwd(5) line from a struct passwd, and returns a pointer to the resulting string. The string is allocated with malloc(3), and it is the caller's responsibility to free it with free(3). The pw_mkdb() function regenerates the password database by running pw_mkdb(8). If user only the record corresponding to that user will be updated. The pw_mkdb() function returns 0 in case of success and -1 in case of failure. The pw_lock() function locks the master password file. It returns 0 in case of success and -1 in case of failure. The pw_scan() function is a wrapper around the internal libc function __pw_scan(). It scans the master password file for a line correspond- ing to the line provided and return a struct passwd if it matched an existing record. In case of failure, it returns NULL. Otherwise, it returns a pointer to a struct passwd containing the matching record. The struct passwd is allocated with malloc(3), and it is the caller's responsibility to free it with free(3). The pw_tempname() function returns the temporary name of the masterfile created via pw_tmp(). The pw_tmp() creates and opens a presumably safe temporary password file. If mfd is a file descriptor to an open password file, it will be read and written back to the temporary password file. Otherwise if should be set -1. The pw_tmp() returns an open file descriptor to the temporary password file or -1 in case of failure. AUTHORS
Portions of this software were developed for the FreeBSD Project by ThinkSec AS and Network Associates Laboratories, the Security Research Division of Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 (``CBOSS''), as part of the DARPA CHATS research program. This manual page was written by Baptiste Daroussin <bapt@FreeBSD.org>. BSD
October 30, 2012 BSD
All times are GMT -4. The time now is 07:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy