LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   i have to modify a line in a file using shell scripts,i dont know how to go about it (https://www.linuxquestions.org/questions/linux-general-1/i-have-to-modify-a-line-in-a-file-using-shell-scripts-i-dont-know-how-to-go-about-it-704463/)

liunx 02-13-2009 12:00 PM

i have to modify a line in a file using shell scripts,i dont know how to go about it
 
the content of the file is more like this

101 bruno alex 29383 2009
102 mary smith 2829 2892
103 junu adama 282 828298
104 wendy will 29373 122

assuming i want to modify the first line with 101 what could possibly be the solution.
the name of the file is details.

repo 02-13-2009 12:07 PM

what have you tried so far?

nflenz 02-13-2009 08:59 PM

Code:

$ sed -i /101/s/bruno/not-bruno/ filename

syg00 02-13-2009 09:10 PM

First post - does this look like homework or not ?.

salasi 02-15-2009 03:19 AM

Quote:

Originally Posted by syg00 (Post 3442905)
First post - does this look like homework or not ?.

Looks like homework to me....

First you have to select something with which to make the change. sed/AWK/python/perl all sound like the kind of thing that you could use, so, having a short list you select a possible candidate (say sed, that seems like a good choice) and read the man page. So you issue the command

'man sed'

and you get information. (If you didn't have a list of possibles, you try 'man -k string' and see if that helps; as an example 'man -k change' shows you a lot of unintresting stuff, but 'man -k edit' gets lists stuff you might actually use).

Having read the man page, you try something. If after that you can't understand what is going on, or there is a definable area that you didn't understand, you could try posting on Linuxquestions to see if someone can help you on to the next stage, telling people what you have tried or what you think. then, whether it is homework or not, someone will probably actually help, rather than giving you a fragment of code that does the job without helping you much

liunx 02-16-2009 11:50 AM

thanks
 
Quote:

Originally Posted by repo (Post 3442534)
what have you tried so far?

i have tired using sed
as in
sed '101d' filename
but its not deleting the line with 101

i am new to shell scripting
and linux. "newbie"

liunx 02-16-2009 11:53 AM

thanks for ur idea
 
i have done that;
i am trying to do it using shell scripts

liunx 02-16-2009 11:56 AM

yes
 
more like it

liunx 02-16-2009 11:57 AM

thanks
 
i ll try it now

jschiwal 02-16-2009 12:22 PM

Quote:

sed '101d' filename
That will delete line 101. Not a line that matches "101".

Be careful which regular expression you use to find a match. To simple a pattern, and you might delete other lines as well.
Use ^, $ and literals (as anchors) to prevent false matches. Test what you have on a larger set. For example, if you wanted to match the line "104 wendy will 29373 122" and a later line had 104 in the 5th column, it would be deleted as well.


All times are GMT -5. The time now is 08:36 AM.