|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
do u mean want to append the lines in a file based on the user inputs ?
|
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
doneoutput 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
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
I think there's more than one way to skin a cat.
![]() |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|