Adding lines at end of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding lines at end of a line
# 8  
Old 05-15-2010
ah...I was really skipping the scripted version myself... It worked so well, I got confused.

Code:
$ echo "The sky is blue.^JI like to eat.^JI like nice cars.^Jstaying healthy is fun." |while read line
> do
>   i=2
>   while [ $i -gt 0 ]
>   do
>     echo "$line"
>     i=$(( $i - 1 ))
>   done
>   i=$(( $i + 1 ))
> done

# 9  
Old 05-15-2010
I am probably using ksh, How can I double-check for sure?
# 10  
Old 05-15-2010
Code:
env |grep sh

But, as methyl has pointed out, the $ following the # in the first line of the script is your problem...most likely.
# 11  
Old 05-15-2010
Ok it works but not the way I want it. I do not want an incremental count. I want instead line 1 to be copied 5 times, line 2 to be copied twice, line 3 to be copied 4 times, and line 4 to be copied 7 times. How can I achieve that?

---------- Post updated at 10:14 PM ---------- Previous update was at 10:10 PM ----------

I am thinking that maybe I need to specify the row number and tell the script to make "x" number of copies for that specific row. How should I script it?
# 12  
Old 05-15-2010
You'd really want to re-wrap it all into its own loop to achieve this:

Code:
my_list='5 2 4 7' 
typeset -i h=1 
for n in $my_list 
do 
   sed -n ${h}p Edit4 |while read line 
   do 
      i=${n} 
      while [ $i -gt 0 ] 
      do 
         echo "$line" 
         i=$(( $i - 1 )) 
      done 
      i=$(( $i + 1 )) 
   done 
   h=$(( $h + 1 )) 
done

# 13  
Old 05-16-2010
When I use this script, I get the following message:

Can't open Edit4
Can't open Edit4
Can't open Edit4
Can't open Edit4
# 14  
Old 05-16-2010
sorry, Edit4 would be replaced with your input filename.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding comma to end of each line if more than 1 line

I have a file with dates as '2013-01-01' '2013-01-02' I want the output to be '2013-01-01','2013-01-02' if there is only 1 entry then there should not be any comma. (6 Replies)
Discussion started by: ATWC
6 Replies

2. Shell Programming and Scripting

awk Adding a Period at the end of a line

I started venturing in learning the art of using AWK/GAWK and wanted to simply added a period from line #11 to line #28 or to the end of the file if there is data. So for example: 11 Centos.NM 12 dojo1 13 redhat.5.5.32Bit 14 redhat.6.2.64Bit... (5 Replies)
Discussion started by: metallica1973
5 Replies

3. 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

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

Adding comma at the end of every line

Hi all, I have this sample file (actual file is larger) and i need to add comma at the end of every line. 1234 4335 232345 1212 3535 Output 1234, 4335, 232345, 1212, 3535, TIA - jak (2 Replies)
Discussion started by: jakSun8
2 Replies

7. 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

8. Shell Programming and Scripting

adding text to the end of lines containing a word

I'm new to shell scripting, and need to add a series of commands to the ends of certain lines of text that contain a keyword. Any easy way to do this? Thanks (2 Replies)
Discussion started by: ironwall
2 Replies

9. 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

10. 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
Login or Register to Ask a Question