Alter a part of a line specified by user


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Alter a part of a line specified by user
# 1  
Old 05-07-2012
Alter a part of a line specified by user

How can I adjust a specific field in a line that the user specifies...

In other words,
I have a file that contains several lines containing several fields separated by a comma.

Code:
(name),(address),(ph. number)

I want to ask the user which record he wants to adjust based on the name.

However, I want to be able to change the number only.

Code:
echo "Which record?"
read record

Then I have no idea how to figure out the next step. Any help?

Last edited by Scrutinizer; 05-07-2012 at 05:30 PM.. Reason: code tags
# 2  
Old 05-07-2012
Well, what's the content of the file look like, and how would the user be specifying which one?
# 3  
Old 05-07-2012
There are several different lines. Each line has a name, an address, and a phone number. The user is asked which entry they want to adjust. They are to enter the name. Once the name is entered they will enter a new number that will be associated with that entry. Then that new number will be updated into that existing file.
# 4  
Old 05-07-2012
Code:
awk -F, -v NAME="$NAME" -v PHONE="$PHONE" -v OFS="," '$1==NAME { $3=PHONE } 1' inputfile > outputfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract part of $USER in script

I need to be able to say "My name is $USER' when I use echo it work, when I use printf it print more 'my last name@.........'. How can I get just the part before the @ sign. I have to use printf. using UNIX. ------ Post updated at 01:17 PM ------ I used the activation code but I still... (2 Replies)
Discussion started by: sheltie042
2 Replies

2. Shell Programming and Scripting

How to remove part of the line from start of the line?

Hello, I am java command from a shell script which will generate the below output on the command prompt signature Base64 :... (10 Replies)
Discussion started by: chetanojha
10 Replies

3. Shell Programming and Scripting

Get second line and append to part of first line

I have a file (test) that looks like below and I am trying to match for *.tif and print the output to another file expecting the output to be something like /opt/apps/image/35645-3456.tif. I would greatly appreciate any ideas you can provide. #cat test /opt/apps/image/3456.tif 35645... (1 Reply)
Discussion started by: Alex A
1 Replies

4. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

5. Red Hat

User is a Part of a Group But Group Details Do Not Show the User

Hi, In the following output you can see the the user "richard" is a member on the team/group "developers": # id richard uid=10247(richard) gid=100361(developers) groups=100361(developers),10053(testers) but in the following details of the said group (developers), the said user... (3 Replies)
Discussion started by: indiansoil
3 Replies

6. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

7. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

8. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
Login or Register to Ask a Question