how to create one newfile and wants include some lines based on user request


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to create one newfile and wants include some lines based on user request
# 1  
Old 03-08-2010
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.
# 2  
Old 03-08-2010
do u mean want to append the lines in a file based on the user inputs ?
# 3  
Old 03-08-2010
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
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

# 5  
Old 03-08-2010
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"

# 6  
Old 03-08-2010
I think there's more than one way to skin a cat. Smilie
# 7  
Old 03-08-2010
MySQL 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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Automaticaly create function based off user input

I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss. If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

How to include menu based options in Shell script?

Hi Friends, I have a menu based tool which requires input/option to proceed further. How to make a shell script ? eg: menu looks like Get_data.sh to continue (y/n) : Here I need to key in "y" to proceed. I want to prepare a script which should consider option y. (5 Replies)
Discussion started by: suresh3566
5 Replies

4. UNIX for Dummies Questions & Answers

Script to capture logs based on REQUEST iD

Hi All, I am a newbie, I am looking for a script that can capture logs based on a request id and store it in tmp folder Log files looks like this" - 2015-07-08 10:59:17,100 INFO RequestId -> 923559008 Inside test method - 2015-07-08 10:59:17,100 INFO RequestId -> 923559008 End of... (2 Replies)
Discussion started by: tsingh
2 Replies

5. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

6. Shell Programming and Scripting

[Request] Copying a file with cp except for the last one or two lines.

Hi folks! I'm new to the unix-side of the world! ;) and I'm trying to learn as much as possible the good stuff that's in it! So.. here comes the point.. as you can see in the title, I need to copy a file but truncating it so that last 1-2 lines are not copied... any suggests from the... (6 Replies)
Discussion started by: WideMind
6 Replies

7. Shell Programming and Scripting

Create a dummy file in all directories that include a .jpg

Hello. My latest project has me with the need for the following script. Basically, any directory that includes a .jpg file needs to also have a ".picture" file created (if it doesn't exist). Here's an example of what I need. /mnt/user/Pictures/2011/Hawaii - 2011/.picture... (11 Replies)
Discussion started by: Davinator
11 Replies

8. Programming

Creating a web based id request form

Please pardon my ignorance, but I need to create a web-based form which can be used to request access to the unix servers in our environment. It just needs to have input fields for basic info (name, dept., etc.), and perhaps a drop-down box with the names of the servers. The form will be submitted... (2 Replies)
Discussion started by: wjssj
2 Replies

9. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

10. Shell Programming and Scripting

Include lines within a script

I want to add lines in my script dynamically. My script: ... echo addscript end addscript ... Lines to add: (can be put in a file and can be added) cp /opt/script1.sh opt/script1_org.sh sed 's/testusr/'${FUNCTID}'/g' /opt/script1.sh > ./tmpfile mv ./tmpfile /opt/script1.sh... (1 Reply)
Discussion started by: chiru_h
1 Replies
Login or Register to Ask a Question