-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
CSᵠ
  • 10,049
  • 9
  • 41
  • 64
user2060673
  • 459
  • 1
  • 4
  • 8

3 Answers3

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
phs
  • 10,687
  • 4
  • 58
  • 84
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

technosaurus
  • 7,676
  • 1
  • 30
  • 52
1
awk '$0="http://"$0' your_file
Vijay
  • 65,327
  • 90
  • 227
  • 319