Sponsored Content
Top Forums Shell Programming and Scripting Need to replace last field in a file,if first field matches Post 302976702 by Sumanthsv on Monday 4th of July 2016 05:52:03 AM
Old 07-04-2016
Need to replace last field in a file,if first field matches

Hi,

Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username.

Scenario:

Code:
cat testfor1
deekshi:x:7082:7082::/home/deekshi:/bin/bash
harini1:x:7083:7083::/home/harini1:/bin/bash

Here,if first field contains "deekshi", then i should replace /bin/bash with /bin/nologin

Expected Output:

Code:
cat testfor1
deekshi:x:7082:7082::/home/deekshi:/bin/nologin
harini1:x:7083:7083::/home/harini1:/bin/bash

As of now i tried like below,

Code:
sed '/deekshi/s|$|/bin/nologin|' testfor1

But its not working


TIA
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to replace a field in one file with a field from another file

I have to replace a field in one file with a field from other file. I came across this awk command to replace a field with one string nawk -F'|' -v OFS='|' '$2="replace"' temp2 > temp3 I need to have something like cut -f2 -d "|" temp1 (a field from other file) instead of 'replace' Is... (8 Replies)
Discussion started by: savant
8 Replies

2. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

3. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

4. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Displaying the first field if the second field matches the pattern using Perl

Hi, I am trying with the below Perl command to print the first field when the second field matches the given pattern: perl -lane 'open F, "< myfile"; for $i (<F>) {chomp $i; if ($F =~ /patt$/) {my $f = (split(" ", $i)); print "$f";}} close F' dummy_file I know I can achieve the same with the... (7 Replies)
Discussion started by: royalibrahim
7 Replies

7. Shell Programming and Scripting

Replace a field with a character as per the field length

Hi all, I have a requirement to replace a field with a character as per the length of the field. Suppose i have a file where second field is of 20 character length. I want to replace second field with 20 stars (*). like ******************** As the field is not a fixed one, i want to do the... (2 Replies)
Discussion started by: gani_85
2 Replies

8. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

9. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

10. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies
NODE.PERMS(5)						     Linux Programmer's Manual						     NODE.PERMS(5)

NAME
node.perms - LinuxNode permissions file. DESCRIPTION
Node.perms file is read at program startup with the knowledge of users username (call), connection type (AX.25, NET/ROM, ROSE, TCP/IP), peers IP address (for TCP/IP) and port name (for AX.25). The first entry matching this information is taken and user is asked for password and given permissions according to it. The lines within node.perms must either be a comment line, which starts with a # in the first column, or a permission entry in the follow- ing format, each field being delimited by white space: username type portname password permissions The field descriptions are: username This is matched against users username (call) without SSID. An asterisk (*) matches any username. type This is matched against the type of the connection to user. Possible values for this field are: * matches any type of connection. ax25 matches users coming in with AX.25. netrom matches users coming in with NET/ROM. rose matches users coming in with ROSE. local matches TCP/IP connections where users host is in "local" network as defined in node.conf(5). ampr matches TCP/IP connections where users host is in amprnet (44.0.0.0/8). inet matches TCP/IP connections where users host is neither in "local" network nor in amprnet. host matches users starting LinuxNode from shell. portname If user is coming in with AX.25 this field is matched against the local port name the user is coming in via. An asterisk (*) matches any port name. password If the previous tree fields match and this field is not a single asterisk (*) the user is asked for a password. The password is then matched against this field. permissions This field represents a a bitmask of operations the user is permitted to do. It is a sum of the values listed here: 1 permits logging in even if no other permissions are given. 2 permits outgoing AX.25 connects. 4 permits outgoing NET/ROM connects. 8 permits telneting to hosts in the "local" network as defined in node.conf(5). 16 permits telneting to hosts in amprnet. 32 permits telneting to hosts neither in the "local" network nor in amprnet. 64 permits using hidden ports in outgoing AX.25 connections. (See HiddenPorts command in node.conf(5).) 128 permits outgoing ROSE connects. 256 The no-escape flag. Disables the escape mechanism for this user. FILES
/etc/ax25/node.perms SEE ALSO
node(8), node.conf(5), axports(5), ax25(4). Linux 16 June 1999 NODE.PERMS(5)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy