Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read the values from a file and write in the output file with som string.

 
Saravanan Mrajan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the input file contains

454545
090900
343434
and the output would look like,

The first value is 454545
The second value is 090900
The third value is 343434

what is the shell script i can try?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Saravanan Mrajan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Wagner wrote:


Thanks. i wrote the script using awk. anyway i will try this code.

can you explain this a little?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Line 1 defines and initializes an array of Strings.
Line 2 init counter n
Line 3 is the head of a for-loop, which reads line by line from the file 'data'.
Line 4 prints to stdout, using the array
Line 5 increases the counter n
Line 6 end of loop

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic