LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2013, 05:00 PM   #1
JimD2009
LQ Newbie
 
Registered: Dec 2013
Posts: 1

Rep: Reputation: Disabled
sed or awk to change a field in a file


I am new to Linux and I'm trying to learn how to edit files with a script. I created a file called "address". I wrote a script where I ask the user to enter their name, street, zip, and state. I'm using ":" to separate the fields. The format looks like this:

peter parker : 32 : main st : 11111 : FL
clark kent : 134 : rainbow rd : 22222 : MI

I now want to add a feature which allows the user to edit a field on a line and then save it back to the original file. An example would be to change peter parker's house number from 32 to 42. My edit feature would ask the user what name they want to search for and then what is the new house number.

I have a basic understanding of awk and sed. I know awk can list all the columns and sed has a search and replace feature. Any help on this would be greatly appreciated.
 
Old 12-08-2013, 02:37 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
First you will need to show us what you have tried and where you are stuck?

On your requirement, you may wish to consider that there could possibly be multiple people with the same name
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with sed and awk to change L-case letters to U-case for specific lines in a file rootaccess Linux - General 12 05-21-2012 02:50 PM
Replace a field for a whole line in the same file, with awk. amwink Programming 12 11-13-2009 06:51 AM
Sed / Awk / removing chars from field 5 only webs Linux - Newbie 11 10-31-2009 03:46 AM
AWK: change a particular field in a csv file help help help!!!! haydar68 Programming 20 08-03-2008 01:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration