Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-08-2010
Registered User
 

Join Date: Sep 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
how to create one newfile and wants include some lines based on user request

I have one request, First it has to create one file and in that file
it has to include some lines based on user request.

Suppose user requested 10, then script needs to add 10 lines like below

QAEVO_A1|A1
QAEVO_A2|A2
QAEVO_A3|A3
QAEVO_A4|A4
QAEVO_A5|A5
QAEVO_A6|A6
QAEVO_A7|A7
QAEVO_A8|A8
QAEVO_A9|A9
QAEVO_10|A10


Thanks,
Sri.
Sponsored Links
    #2  
Old 03-08-2010
Registered User
 

Join Date: Feb 2010
Location: /root
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
do u mean want to append the lines in a file based on the user inputs ?
Sponsored Links
    #3  
Old 03-08-2010
thillai_selvan's Avatar
Registered User
 

Join Date: Feb 2010
Location: Chennai
Posts: 190
Thanks: 0
Thanked 1 Time in 1 Post
Try this code.

Code:
echo "Enter a request"
read n
#echo $n
for i in  `seq 1 $n`
do
        echo QAEVO_A1\|A$i | cat >> output
done

output

Code:
sh request.sh
Enter a request
5

cat output

QAEVO_A1|A1
QAEVO_A1|A2
QAEVO_A1|A3
QAEVO_A1|A4
QAEVO_A1|A5

    #4  
Old 03-08-2010
Nila's Avatar
Registered User
 

Join Date: Feb 2010
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Try this script,


Code:
#!/bin/sh
>output_file
echo "Enter the value in digit";
read value
for ((i=1; i<=$value; i++))
do
        echo "QAEVO_A${i}|A${i}"  >>output_file
done

Sponsored Links
    #5  
Old 03-08-2010
karthigayan's Avatar
Registered User
 

Join Date: Apr 2009
Location: India , Chennai
Posts: 137
Thanks: 0
Thanked 3 Times in 3 Posts
Sample code,


Code:
echo -n " Enter the file name to create : "
read file
echo -n " Enter the number of lines to add :"
read lines
i=1;
while [ $i -le $lines ]
do
        echo   "QAEVO_A$i|A$i" >>$file
        let i=$i+1;
done
echo  " File $file created"

Sponsored Links
    #6  
Old 03-08-2010
Registered User
 

Join Date: Feb 2010
Posts: 123
Thanks: 2
Thanked 1 Time in 1 Post
I think there's more than one way to skin a cat.
Sponsored Links
    #7  
Old 03-08-2010
Registered User
 

Join Date: Feb 2010
Location: /root
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Solution

I don't have an idea of your inputs , but If you want to append a line in a file with a loop using script then you might refer this script

Code:
read num  # Get an input 

for i in `seq 1 $num`
do
   
        cat >>filename <<EOF;
line you want to add in a file ${array[$i]}   # array can be variable of value , you can modify this line as u desire 
EOF
done

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
create pipes based on the column ramse8pc Shell Programming and Scripting 3 01-27-2010 08:46 PM
create variable name based on another variable's value benefactr Shell Programming and Scripting 2 11-01-2007 11:27 AM
Include lines within a script chiru_h Shell Programming and Scripting 1 09-22-2006 12:51 PM
I create user but i cant login the user i created. jerome UNIX for Dummies Questions & Answers 5 06-09-2006 05:08 PM
Other than root user .Normal user is unable to create files mallesh UNIX for Advanced & Expert Users 1 06-22-2005 12:18 PM



All times are GMT -4. The time now is 12:53 AM.