appending running numbers on a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers appending running numbers on a variable
# 1  
Old 10-22-2010
appending running numbers on a variable

hi guys,

would appreciate some help here. I need to append running numbers using sed onto a variable that contain a list of IP addresses. I'm basically stuck on the running number part. e.g.

1. 10.0.0.1
2. 10.0.0.2
3. 10.0.0.3
# 2  
Old 10-22-2010
please give more input what did you try so far ?
what do you mean by "running"?
# 3  
Old 10-22-2010
Quote:
Originally Posted by ctsgnb
please give more input what did you try so far ?
what do you mean by "running"?
i meant ascending numbering

e.g.

input:

Code:
10.0.0.1
10.0.0.2
10.0.0.3

output:
Code:
1. 10.0.0.1
2. 10.0.0.2
3. 10.0.0.3


Last edited by vgersh99; 10-22-2010 at 11:26 AM.. Reason: code tags, please!
# 4  
Old 10-22-2010
Quote:
sed = input | sed 'N;s/\n/. /'
# 5  
Old 10-22-2010
Code:
sed '=' input | sed 'N;s/\n/ /' > output

# 6  
Old 10-22-2010
Code:
cat -b input > output

or
Code:
cat -n input > output

or in ksh (don't know whether bash has the same $LINENO built in variable
Code:
( { while read line ; do echo "$LINENO. $a" ; done } <input ) >output

# 7  
Old 10-22-2010
Quote:
Originally Posted by vgersh99
Code:
sed '=' input | sed 'N;s/\n/ /' > output

Code:
`printf "$VAR" | sed 'N;s/\n/. /'`

sorry, can't seem to get it to work



---------- Post updated at 10:14 AM ---------- Previous update was at 09:56 AM ----------




Quote:
Originally Posted by ctsgnb
Code:
cat -b input > output

or
Code:
cat -n input > output

or in ksh (don't know whether bash has the same $LINENO built in variable
Code:
( { while read line ; do echo "$LINENO. $a" ; done } <input ) >output

it's odd I can't do cat in my script

Code:
cat -n "$VAR"

Code:
error:
cat: cannot open

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

2. UNIX for Dummies Questions & Answers

Appending a column of numbers in ascending order to a text file

I have a text file where I want to append a column of numbers in ascending orders. Input: 57 abc 25 def 32 ghi 54 jkl Output:57 abc 57 abc 1 25 def 2 32 ghi 3 54 jkl 4 How do I go about doing that? Thanks! (11 Replies)
Discussion started by: evelibertine
11 Replies

3. Shell Programming and Scripting

changing and appending numbers

I have a file that looks like below but i need to add the second part to the first meaning in the part where it goes from 14 to 1 in the first column to go to 14 to 15 and the same with the right side going from 2 to 1 to go to 2 to 3. THanks 1 176.587 0.015 C 1 2 57.351 ... (4 Replies)
Discussion started by: olifu02
4 Replies

4. UNIX for Dummies Questions & Answers

Adding a running sequence number while appending 2 files

Hi, I have to append 2 files and while appending i need to add a running sequence number (counter ) for each line at the first column. For e.g. If file x contains details as below. Tom Dick Harry Charlie and file y contains Boston Newyork LA Toledo Then the new file should... (1 Reply)
Discussion started by: kalyansid
1 Replies

5. Shell Programming and Scripting

Appending value to variable

I have a Query! by using command cat >> file1 we can append data's to a already existing file, Similarly is it possible to append a data to a variable. Thanks in Advance!! (2 Replies)
Discussion started by: gwgreen1
2 Replies

6. Shell Programming and Scripting

appending zeros to numbers using awk

hi i want to append zeros to a given number ( varying digits). the total length of the output should be 10 digits. For example: 1)input is var=347 output should be NewVar=0000000347 2) input is var=123456 output should be NewVar=0000123456 i am able to acheive this using typeset... (1 Reply)
Discussion started by: somi2yoga
1 Replies

7. Shell Programming and Scripting

Appending data into a variable

Hi, I would like to know if it's possible to append data into a variable, rather than into a file. Although I can write information into a temporary file in /tmp, I'd rather if possible write into a variable, as I don't like the idea that should my script fail, I'll be polluting the server with... (5 Replies)
Discussion started by: michaeltravisuk
5 Replies

8. Shell Programming and Scripting

appending space to variable

Hi I need to write a script where there the user enters 3 input parameter variable number the program should ask the user left or right if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is... (5 Replies)
Discussion started by: viv1
5 Replies

9. Shell Programming and Scripting

Appending to a variable?

Hey, I'm creating a custom useradd script, and I'm giving the option to add secondary groups. Basically what I want to do is ask for the name of the group, you type in the group you want to add, it assigns that group name to the variable $sgroup. Then the scripts asks if you want add another. If... (0 Replies)
Discussion started by: paqman
0 Replies

10. Shell Programming and Scripting

appending spaces to a variable

Hi All, I have a requirement, in which i have to append some spaces to the variable, and then send it to another function. I am new to the UNIX shell programming. Ultimately the length of the string should be 40 characters. exp: Login = "rallapalli" (length = 10) i have to append 30 spaces to... (2 Replies)
Discussion started by: rallapalli
2 Replies
Login or Register to Ask a Question