-1

I have a task to enter word http:// at begining of each line of text file. How this can be done using shell script

My text file is like:

agr.nc.in
mpi.ni.in
ir.o.in
chemis.go.in
da.ni.in
dgt.go.in
dgn.go.in

output file should be like:

http://agr.nc.in
http://mpi.ni.in
http://ir.o.in
http://chemis.go.in
http://da.ni.in
http://dgt.go.in
http://dgn.go.in
1
  • The regex for "beginning of line" is ^. Commented Aug 14, 2013 at 6:19

3 Answers 3

1

You can use sed:

$ echo -e 'foo\nbar\nbaz'
foo
bar
baz
$ echo -e 'foo\nbar\nbaz' | sed 's|^|http://|'
http://foo
http://bar
http://baz
Sign up to request clarification or add additional context in comments.

Comments

1

to edit in place with sed:

sed -i 's|^|http://|' infile

to do it with shell only:

while read LINE || [ "$LINE" ];do echo "http://$LINE";done <infile >outfile

Comments

1
awk '$0="http://"$0' your_file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.