Sponsored Content
Top Forums Shell Programming and Scripting Replace a specific column with a specific value Post 302915189 by RavinderSingh13 on Monday 1st of September 2014 09:41:34 AM
Old 09-01-2014
Litu,

This solution will work when you need to add variable at the last of the line. If any conditions are there for the variable to be added please let us know with full description, but if you need to add variable at last solution will work. Explaination of the solution is as follows.
Code:
echo "password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok" | awk '$(NF+1)="remeber=10" 1'

$(NF+1) means I am adding one more field at last of the line as a line will have acually NF number of fields only, then I am giving 1 which means I am making condition part set to true so be default print operation will take place. Please refer man awk also for same, will be helpful for you.

EDIT: Please use the following solution for same as above solution will not give requested output, thanks Franklin for pointing it out.

Code:
awk '$(NF+1)="remeber=10"' filename

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-01-2014 at 11:44 AM.. Reason: Adding correct solution to the thread
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace a specific word in specific column?

Hi My orginal file is like (100s of lines) id host ip location remarks 1 host1 ip1 - xxx 2 host2 ip2 - xxx 3 host3 ip3 - xxx -- -- 9 host9 ip9 - xxx I have a ref file like host1 location1 host2 location2 host3 location3 -- --... (6 Replies)
Discussion started by: ./hari.sh
6 Replies

2. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

3. Shell Programming and Scripting

Help with replace column data with specific word

Input file: Populus_trichocarpa 30 0 50 0 0 US Vitis_vinifera 1 18 2 8 6 US Populus_trichocarpa 1 5 100 0 0 US Arabidopsis_lyrata_subsp._lyrata 0 90 0 0 0 US Glycine_max 0 2 3 0 70 UK Desired output file: Populus_trichocarpa YES NO YES NO NO US Vitis_vinifera YES YES YES YES YES US... (4 Replies)
Discussion started by: perl_beginner
4 Replies

4. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

5. Shell Programming and Scripting

Bash Replace value in specific column

Hi all, I have two files with the following format: file1 BBB;33 AAA;2 CCC;5 file2 5;.;.;. 33;.;.;. The first file contain a list of code and numbers. The second file only the number. I would like to replace the corresponding code in the first column of the file1 with the... (3 Replies)
Discussion started by: g256
3 Replies

6. Shell Programming and Scripting

Help with replace specific column command

Input file: ASD_QAW 12 A_@ AE_AQ 21 PA_123 ASDA_@ 23 ADA_AS . . Output file: ASD_QAW 12 A @ AE_AQ 21 PA 123 ASDA_@ 23 ADA AS . . Do anybody know how to just specific and replace "_" in column 3 with tab delimiter (\t)? Thanks for advice. (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. Shell Programming and Scripting

How to replace a character in a specific column in a file?

This is a file that I have test line 1 (55) ) test line 2 (45) ) I would like to change all the parens in position 1 of this file to a ); i only want to check position 1 in every line of the file. I have tried different varations of sed, but cannot seem to be able to limit it to... (1 Reply)
Discussion started by: JoeG
1 Replies

8. Shell Programming and Scripting

Search Replace Specific Column using RegEx

Have Pipe Delimited File: > BRYAN BAKER|4/4/2015|518 VIRGINIA AVE|TEST > JOE BAXTER|3/30/2015|2233 MockingBird RD|ROW2On 3rd column where the address is located, I want to add a space after every numeric value - basically doing a "s//&\ / ": > BRYAN BAKER|4/4/2015|5 1 8 VIRGINIA AVE|TEST > JOE... (5 Replies)
Discussion started by: svn
5 Replies

9. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

10. Shell Programming and Scripting

Replace specific column delimiter

Hi All, I have a file with a pipe delimiter. I need to replace the delimiter with html tags. I managed to get all the delimiters replaced along with first and last but the requirement is that I need to change 7th delimiter with slight change. File1: ... (2 Replies)
Discussion started by: shash
2 Replies
PAM_UNIX(8)							 Linux-PAM Manual						       PAM_UNIX(8)

NAME
pam_unix - Module for traditional password authentication SYNOPSIS
pam_unix.so [...] DESCRIPTION
This is the standard Unix authentication module. It uses standard calls from the system's libraries to retrieve and set account information as well as authentication. Usually this is obtained from the /etc/passwd and the /etc/shadow file as well if shadow is enabled. The account component performs the task of establishing the status of the user's account and password based on the following shadow elements: expire, last_change, max_change, min_change, warn_change. In the case of the latter, it may offer advice to the user on changing their password or, through the PAM_AUTHTOKEN_REQD return, delay giving service to the user until they have established a new password. The entries listed above are documented in the shadow(5) manual page. Should the user's record not contain one or more of these entries, the corresponding shadow check is not performed. The authentication component performs the task of checking the users credentials (password). The default action of this module is to not permit the user access to a service if their official password is blank. A helper binary, unix_chkpwd(8), is provided to check the user's password when it is stored in a read protected database. This binary is very simple and will only check the password of the user invoking it. It is called transparently on behalf of the user by the authenticating component of this module. In this way it is possible for applications like xlock(1) to work without being setuid-root. The module, by default, will temporarily turn off SIGCHLD handling for the duration of execution of the helper binary. This is generally the right thing to do, as many applications are not prepared to handle this signal from a child they didn't know was fork()d. The noreap module argument can be used to suppress this temporary shielding and may be needed for use with certain applications. The password component of this module performs the task of updating the user's password. The default encryption hash is taken from the ENCRYPT_METHOD variable from /etc/login.defs The session component of this module logs when a user logins or leave the system. Remaining arguments, supported by others functions of this module, are silently ignored. Other arguments are logged as errors through syslog(3). OPTIONS
debug Turns on debugging via syslog(3). audit A little more extreme than debug. nullok The default action of this module is to not permit the user access to a service if their official password is blank. The nullok argument overrides this default. try_first_pass Before prompting the user for their password, the module first tries the previous stacked module's password in case that satisfies this module as well. use_first_pass The argument use_first_pass forces the module to use a previous stacked modules password and will never prompt the user - if no password is available or the password is not appropriate, the user will be denied access. nodelay This argument can be used to discourage the authentication component from requesting a delay should the authentication as a whole fail. The default action is for the module to request a delay-on-failure of the order of two second. use_authtok When password changing enforce the module to set the new password to the one provided by a previously stacked password module (this is used in the example of the stacking of the pam_cracklib module documented below). not_set_pass This argument is used to inform the module that it is not to pay attention to/make available the old or new passwords from/to other (stacked) password modules. nis NIS RPC is used for setting new passwords. remember=n The last n passwords for each user are saved in /etc/security/opasswd in order to force password change history and keep the user from alternating between the same password too frequently. Instead of this option the pam_pwhistory module should be used. shadow Try to maintain a shadow based system. md5 When a user changes their password next, encrypt it with the MD5 algorithm. bigcrypt When a user changes their password next, encrypt it with the DEC C2 algorithm. sha256 When a user changes their password next, encrypt it with the SHA256 algorithm. The SHA256 algorithm must be supported by the crypt(3) function. sha512 When a user changes their password next, encrypt it with the SHA512 algorithm. The SHA512 algorithm must be supported by the crypt(3) function. blowfish When a user changes their password next, encrypt it with the blowfish algorithm. The blowfish algorithm must be supported by the crypt(3) function. rounds=n Set the optional number of rounds of the SHA256, SHA512 and blowfish password hashing algorithms to n. broken_shadow Ignore errors reading shadow information for users in the account management module. minlen=n Set a minimum password length of n characters. The max. for DES crypt based passwords are 8 characters. Invalid arguments are logged with syslog(3). MODULE TYPES PROVIDED
All module types (account, auth, password and session) are provided. RETURN VALUES
PAM_IGNORE Ignore this module. EXAMPLES
An example usage for /etc/pam.d/login would be: # Authenticate the user auth required pam_unix.so # Ensure users account and password are still active account required pam_unix.so # Change the users password, but at first check the strength # with pam_cracklib(8) password required pam_cracklib.so retry=3 minlen=6 difok=3 password required pam_unix.so use_authtok nullok md5 session required pam_unix.so SEE ALSO
login.defs(5), pam.conf(5), pam.d(5), pam(8) AUTHOR
pam_unix was written by various people. Linux-PAM Manual 06/17/2014 PAM_UNIX(8)
All times are GMT -4. The time now is 05:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy