Visit Our UNIX and Linux User Community


Read a text file and print the content..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read a text file and print the content..
# 1  
Old 06-09-2010
Java 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
Code:
g
go
goo
goog
googl
google

like this Using unix Shell scripting...

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

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by samupnl; 06-10-2010 at 02:39 AM.. Reason: code tags
# 2  
Old 06-09-2010
Code:
$> 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.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 06-09-2010
Code:
awk '{s="";for(i=1;i<=NF;i++)print s=s$i}' FS= infile

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 06-09-2010
Computer

Code:
fold -w1 file | perl -nle 'push @x, $_; print @x'

This User Gave Thanks to pseudocoder For This Post:
# 5  
Old 06-10-2010
Quote:
Originally Posted by zaxxon
Code:
$> 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.
without using awk..i need the scripts
# 6  
Old 06-10-2010
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.
# 7  
Old 06-10-2010
MySQL

Code:
[root@sistem1lnx ~]# cat google
google
[root@sistem1lnx ~]# ./script google
g
go
goo
goog
googl
google

Code:
 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 Smilie
When you start to share your ideas then we try to help you always Smilie

Good works
Good lucks
Regards ygemici

Last edited by ygemici; 06-10-2010 at 06:06 AM..
This User Gave Thanks to ygemici For This Post:

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

2. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

3. Shell Programming and Scripting

Read from text file;format and print output

Hi Following is the assumed input... Symmetrix ID : 12345 Originator Port wwn : 123456789 User-generated Name : 123456789/123456789 Sym Dev Dir:P LUN ------ ----- ----------------------- ---- --- ---- ---- ---- ------- 1234 ... (4 Replies)
Discussion started by: maddy.san
4 Replies

4. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

Hello everyone, I work under Ubuntu 11.10 (c-shell) I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment. I will show you an example: - On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Discussion started by: tenteyu
1 Replies

5. Shell Programming and Scripting

Print @array content to a file

Hi, as the title, I have an array @f_lines with gene information in it. How can I put the content of @f_lines into a file so that I can read it? I tried this: open(OUTPUT, "file"); # put gene information in this file; @f_lines = ("gene1", "gene2", "gene3"...); # gene information; print... (3 Replies)
Discussion started by: lyni2ULF
3 Replies

6. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

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... (1 Reply)
Discussion started by: samupnl
1 Replies

8. Shell Programming and Scripting

How to read file and only output certain content

Hi - I have a file containing data like :- cn=tommy,cn=users,c=uk passwordexpirydate=20100530130623z cn=jane,cn=users,c=uk passwordexpirydate=20100423140734z cn=michael,cn=users,c=uk passwordexpirydate=20100331020044z I want to end up with a file that looks like:-... (6 Replies)
Discussion started by: sniper57
6 Replies

9. Shell Programming and Scripting

read file content

i have one file abhi.txt its contents are home8/mc09ats/UnixCw/backup/file1 home8/mc09ats/file2 i want to read this content of file using while loop.. in this i want to seperate the content as follows path=home8/mc09ats/UnixCw/backup file=file1 echo path echo file can you... (1 Reply)
Discussion started by: AbhijitIT
1 Replies

10. Shell Programming and Scripting

read a file and use the content for mapping

help me pls.. :( i want to read a mapping file. Below is the content of my mapping file. 6221,189,SMSC1,OMC1,WAP1 6223,188,SMSC2,OMC2,WAP2 so when my program running msisdn="622130302310" while not EOF if substring($msisdn,1,4) == "6221" -- > "6221" read from the file then echo... (0 Replies)
Discussion started by: voidmain
0 Replies

Featured Tech Videos