For Loop and assigning Value using Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For Loop and assigning Value using Sed
# 1  
Old 05-26-2010
Question For Loop and assigning Value using Sed

Hi,

Please help me writing for loop to fetch data and store in variable from a text file which contains data as below:

Code:
 
12
 
46
 
56
 
5466
 
111

There are 40 lines of data...!!!!
I jus need all data from line no 4 to 40 ie data for 4,6,8......40.
# 2  
Old 05-26-2010
Please can you post the output expected ?

I'm not sure of your requirement.
# 3  
Old 05-26-2010
ya sure........!!!!

i want to send automated mail using script which will be like this....

Code:
table name                  count1                count2           count3
-------------------------------------------------------------------
table1                        11111                  22222            33333

and so on...

this counts i want to pull from a text file and assign it to variables so that i can form table like this.

now while pulling data the txt file contains data as

Code:
1
 
2
 
3
 
4

ie a new line after every data and one new line at the begining too....

so want to use for loop to go thorugh data and store it in variable so that i can use it to form above table....

Hope this xplainsss...!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assigning values to 2 variables within for loop

Hi All, Is it possible to grep for two files and assign their names to two separate variables with for loop? I am doing the below currently: if then for fname in $( cd $dirA ; ls -tr | grep "^Ucountry_file$") do InFile=$dirA/$fname ... (4 Replies)
Discussion started by: swasid
4 Replies

2. Shell Programming and Scripting

[Solved] Assigning a value to a variable name then running a loop on these values

Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer. I have input files containing something like File 1 Apples Apples Apples Apples File 2 Bananas Bananas Bananas Bananas (4 Replies)
Discussion started by: hubleo
4 Replies

3. Shell Programming and Scripting

Need help in assigning output of n commands to n variables automatically inside a for loop

Please help me to automatically assign the output of awk command to the variables cs3, cs4, cs5 and cs6 using a for loop. The below code is not working. for i in 3 4 5 6 do cs$i=`awk -F"|" 'BEGIN{sum=0}{sum=sum+$'$i'}END{printf("%d\n", sum)}' css` done echo $cs3 $cs4 $cs5 $cs6 (9 Replies)
Discussion started by: thulasidharan2k
9 Replies

4. Solaris

For loop variable not assigning

Hi , i am using below code print the PATH value inside for loop but it's printing just PATHD & not the original value which i defined. #!/usr/bin/bash PATHD1=/spp/sp/LIVE export PATHD1 PATHD2=/spp/sp/TEST export PATHD2 j=2 for (( i = 1 ; i <= j ; i++ )) do PATH_DIR=PATH$i echo PATHD$i... (2 Replies)
Discussion started by: panneer76
2 Replies

5. Shell Programming and Scripting

retreiving and assigning values and manipulating string in a for loop

Hi I am new to shell scripting and i am preparing a script. for now i am work on a sub part of it..but i am unable to make it work. --- the test code that i am working on -------------------------- IFS="" Sample_eve=`psg proc_s | grep tY` n=0 for line in $Sample_eve... (41 Replies)
Discussion started by: Anteus
41 Replies

6. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

7. Shell Programming and Scripting

Assigning values to an array via for/while loop

I need to do something like this: for i in 1 2 3 4 5; do arr=$(awk 'NR="$i" { print $2 }' file_with_5_records) done That is, parse a file and assign values to an array in an ascending order relative to the number of record in the file that is being processed on each loop. Is my... (2 Replies)
Discussion started by: fiori_musicali
2 Replies

8. Shell Programming and Scripting

foor loop is not working while assigning to variable

Hi All, While executing following for loop in unix, it is working fine. sum=0 tot_amt=`for i in `cat amt` do sum=`echo "$sum + $i"|bc` done` But if i assing this loop in a variable it is not working. The error is so and done is unexpected. tot_val=`sum=0;tot_amt=`for i in... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

9. Shell Programming and Scripting

Assigning inside for loop

If I have 3 variables and I want to check if any of these is null. If one of them is null then it should be assigned a value of 0.I have the following code below. The output should be 0 is A, 11 is B, 33 is C $a= $b=11 $c=33 $echo $a $b $c $11 33 for i in "${a}" "${b}" "${c}"; do ... (2 Replies)
Discussion started by: thana
2 Replies

10. Shell Programming and Scripting

assigning variables in sed command

I need to assign a variable within a variable in a sed command. I tried doing the following in c shell. set left = 1 set right = 2 set segment = qwerty sed -n -e "/$segment{$left}/,/$segment{$right}/p" file.txt what is wrong with this syntax? (3 Replies)
Discussion started by: wxornot
3 Replies
Login or Register to Ask a Question