Adding patterns with increasing numbers at the end of every line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding patterns with increasing numbers at the end of every line
# 1  
Old 09-09-2011
Adding patterns with increasing numbers at the end of every line

Hi All,

I have a file which has some Linux commands in every line like

Code:
more 456.dat
more 3232.dat
more 433.dat

I want to add texts like this at the end of every line:


Code:
more 456.dat > 1.txt
more 3232.dat > 2.txt
more 433.dat > 3.txt

So, that the result of more goes into 1.txt 2.txt and 3.txt respectively.

I know how to add numbers at the end of evry line

Code:
awk '{print $0 ,FNR}' file

But I don't know how to add other texts like > and .txt I am using Linux with BASH.
# 2  
Old 09-09-2011
Code:
awk '{ print $0 " > " FNR ".txt" }' file

Awk uses juxtaposition as a string concatenation operator.
This User Gave Thanks to yazu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding semicolon at the end of each line

Hi, I have a script which I need to change. I want to add a semicolon at the end of each line where the line starts with "grant" for e.g. create table(.... ); grant select on TABL1 to USER1 grant select on TABL1 to USER2should become create table(.... ); grant select on TABL1 to... (3 Replies)
Discussion started by: pparthiv
3 Replies

2. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

3. Shell Programming and Scripting

Script adding ^M to end of line

I trying to make a simple script to get info from remote servers my problem is the output of this line- SERVER_NAME=`ssh -t $USER@$REMOTESERVER 'hostname'`the output is linux1^M I would like to remove the ^M where is my error? Many Thanks -Steve (1 Reply)
Discussion started by: shoodlum
1 Replies

4. Shell Programming and Scripting

adding characters end of line where line begins with..

Hi all, using VI, can anyone tell me how to add some characters onto the end of a line where the line begins with certain charactars eg a,b,c,......., r,s,t,........, a,b,c,......., all lines in the above example starting with a,b,c, I want to add an x at the end of the line so the... (6 Replies)
Discussion started by: satnamx
6 Replies

5. Shell Programming and Scripting

Adding lines at end of a line

This is what I want to do. I want to write a script that reads each line (of the highlighted file below) and add a specific number of blank lines (sometime 2, 3 or 5 lines) at the end of each line while copying that line. For example, here is the input. The sky is blue. I like to eat. I like... (19 Replies)
Discussion started by: Ernst
19 Replies

6. UNIX for Dummies Questions & Answers

Adding Numbers in a line from a file

Hello everyone ! Ive searched everywhere and still havnt found enough information to help me overcome (what seems like) a small problem I have created a temporary file in which i store numbers which a seperated by a space, eg) 5 10 46 23 866 392 i wish to take the numbers for each line... (2 Replies)
Discussion started by: healwithchaos
2 Replies

7. UNIX for Advanced & Expert Users

Add line numbers to end of each line

Hi i would like to add line numbers to end of each line in a file. I am able to do it in the front of each line using sed, but not able to add at the end of the file. Can anyone suggest The following code adds line number to start of each line sed = filename | sed 'N;s/\n/\t/' how can i... (5 Replies)
Discussion started by: rudoraj
5 Replies

8. Shell Programming and Scripting

adding semicolumn at end of line

Hi , I need to add semicolumn at the end of each line in a file. can any one help me in this? Thanks in advance (2 Replies)
Discussion started by: scorpio
2 Replies

9. Shell Programming and Scripting

Adding new line at the end of file

Hi I have few files. For some files the cursor is at the end of last line. For other files, cursor is at the new line at the end. I want to bring the cursor down to next line for the files that are having cursor at the end of last line In otherwords, I want to introduce a blank line at the... (5 Replies)
Discussion started by: somesh_p
5 Replies

10. Solaris

Need help capturing end of line numbers

Hello All, Currently I am attempting to write a script which will capture a number at the end of a line. The line which I am searching through ends as follows: word word=number for example word word=3 OR word word=15 I am stuck on how to capture whatever is to the right... (3 Replies)
Discussion started by: icalderus
3 Replies
Login or Register to Ask a Question