Computing.Net > Forums > Unix > Unix scripting

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix scripting

Reply to Message Icon

Name: wrwe
Date: November 3, 2008 at 08:34:08 Pacific
OS: xp
CPU/Ram: core 2 dual 2gb
Comment:

Hello, i'm new with the scripting on unix and
i need such script or maby something to that
way:

I need to change the the first word in every
new line to a given word. Using just /bin/sh
( not using sed, awk, perl and ect).

I would be very grateful.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 3, 2008 at 10:15:25 Pacific
Reply:

I won't do all of your homework, but I'll do the hard part. Assuming a field separator of white space, this reads the first word and the restofthe line:


#/bin/sh

while read firstword restofline
do
echo $firstword
firstword="whatever"
done < datafile.txt


#
All you have to do is glue firstword and restofline back together.

0

Response Number 2
Name: wrwe
Date: November 9, 2008 at 11:39:02 Pacific
Reply:

thanks for reply, i have it done. But now
i'am interested to write it usig awk and sed.
Maby somebody could help me with that?


0

Response Number 3
Name: nails
Date: November 10, 2008 at 10:36:02 Pacific
Reply:


# for awk, look at section 3.4 changing the contents of a field:

http://www.gnu.org/software/gawk/ma...


# IMO, sed isn't the best choice for changing fields, but try this link:

http://www.grymoire.com/Unix/Sed.html


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix scripting

Unix Script ignoring cmd line vars www.computing.net/answers/unix/unix-script-ignoring-cmd-line-vars/6193.html

Run a Unix Script from VB or ASP www.computing.net/answers/unix/run-a-unix-script-from-vb-or-asp-/4384.html

help redoing unix script student db www.computing.net/answers/unix/help-redoing-unix-script-student-db/5151.html