Read a text file and print the content..

hello all
i request you to give the solution for the following problem..

I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print

g
go
goo
goog
googl
google

like this Using unix Shell scripting...

without using awk i need the scripts...
please help me
thanks

$> awk '{for(x=1;x<=length($0);x++){print substr($0,0,x)}}' file
g
go
goo
goog
googl
google

Your post looks a bit like homework, if this is the case obeye the forum rules for posting homework.

1 Like
awk '{s="";for(i=1;i<=NF;i++)print s=s$i}' FS= infile
1 Like
fold -w1 file | perl -nle 'push @x, $_; print @x'
1 Like

without using awk..i need the scripts

It's amazing how you manage to both quote the guy accusing you of doing homework, and confirm that you're doing homework in the same post.

[root@sistem1lnx ~]# cat google
google
[root@sistem1lnx ~]# ./script google
g
go
goo
goog
googl
google
 cat script
#!/bin/bash
xcount=$( (cat google | grep -o "." | wc -l) )
for i in $(seq 1 $xcount)
do
    cat $1 | fold -w$i | sed -n '1p'
  done

I hope give a idea this..
And you must try to do your homework yourself :slight_smile:
When you start to share your ideas then we try to help you always :wink:

Good works
Good lucks
Regards ygemici

1 Like

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.