Sponsored Content
Top Forums Shell Programming and Scripting Adding new line at the end of file Post 302143978 by radoulov on Monday 5th of November 2007 04:47:20 PM
Old 11-05-2007
Quote:
Originally Posted by somesh_p
Yes.. it is working fine for the files that doens't have a blank line at the end of file

But, if the file already contains a blank line at the end, the modified file is becoming zero bytes. It shouldn't modify the file, if it already has blank line at the end
[...]
I told you the command is:

Code:
sed '${/^$/!s/$/\
/;}' filename

and NOT:

Code:
sed '${/^$/!s/$//;}'

It works even on my old Solaris Smilie

Code:
$ cat file1
line1
line2
line3
line4
$ cat file2
line1
line2
line3
line4

$ sed '${/^$/!s/$/\
> /;}' file1
line1
line2
line3
line4

$ sed '${/^$/!s/$/\
/;}' file2
line1
line2
line3
line4

$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding text to end of each line in a file

I'm needing to add a "hour:min" to the end of each line in a document. The document in this case is only going to be one line. if this inserts it at the end, what needs to be changed to add something at the end... /bin/echo "%s/^/$filler/g\nwq!" | ex -s $oFile Thank you... (2 Replies)
Discussion started by: cubs0729
2 Replies

2. Shell Programming and Scripting

Grabing Date from filename and adding to the end of each line in the file.

Hi, I have 24 .dat files something like below. The file name starts with “abc” followed by two digit month and two digit year. Is there a way to grab the month and year from each filename and append it to the end of each line. Once this is done I want to combine all the files into file... (1 Reply)
Discussion started by: rkumar28
1 Replies

3. Shell Programming and Scripting

Adding multiple line at the end of the file

I have 2 files which contains the following lines file1.txt line4 line5 line6 file2.txt line1 line2 line3 When i execute a script , I want my file2.txt will looks like this: line1 line2 line3 line4 line5 (2 Replies)
Discussion started by: kaibiganmi
2 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

help with sed adding line to end of file

sed '$a\ hello' books hi i am trying to use sed to append hello to the end of the file books, but for some reason i can't get it work. It keeps sayin command garbled. Anyone know what I'm doing wrong. this is in a ksh script as well. (3 Replies)
Discussion started by: bjhum33
3 Replies

6. Shell Programming and Scripting

adding line number to *end* of records in file

Given a file like this: abc def ghi I need to get to somestandardtext abc1 morestandardtext somestandardtext def2 morestandardtext somestandardtext ghi3 morestandardtext Notice that in addition to the standard text there is the line number added in as well. What I conceived is... (4 Replies)
Discussion started by: edstevens
4 Replies

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

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

9. Shell Programming and Scripting

Adding text to the end of the specific line in a file(only to the first occurrence of it)

Hi, I want to add a text to the end of the specific line in a file. Now my file looks like this: 999 111 222 333 111 444 I want to add the string " 555" to the end of the first line contaning 111. Moreover, I want to insert a newline after this line containg the "000" string. The... (8 Replies)
Discussion started by: wenclu
8 Replies

10. Shell Programming and Scripting

Help on Adding one counter loop at the end of each line in a file

Hello All, I have file a.txt I want to add a counter loop at the end of each line in a file ill explain: i have a site h**p://test.test=Elite#1 i want to add a a counter to the number at the end of the file, that it will be like this urlLink//test.test=Elite#1 urlLink//test.test=Elite#2... (3 Replies)
Discussion started by: nexsus
3 Replies
cam(1)							      General Commands Manual							    cam(1)

NAME
cam - CPU'S AUDIO MIXER for Linux SYNOPSIS
cam [-v x,y] [--volume x,y] [-b x,y] [--bass x,y] [-t x,y] [--treble x,y] [-s x,y] [--synth x,y] [-p x,y] [--pcm x,y] [-S x,y] [--speaker x,y] [-l x,y] [--line x,y] [-m x,y] [--mic x,y] [-c x,y] [--cd x,y] [-M x,y] [--mixer x,y] [-a x,y] [--altpcm x,y] [-r x,y] [--reclev x,y] [-i x,y] [--igain x,y] [-o x,y] [--ogain x,y] [-l1 x,y] [--line1 x,y] [-l2 x,y] [--line2 x,y] [-l3 x,y] [--line3 x,y] [-3d 1|0] [--3dse 1|0] [-agc 1|0] [--agc 1|0] [-h] [-?] [--help] [-get] [-save] [-getfile filename] [-savefile filename] xcam DESCRIPTION
This is an audio mixer for Linux. You have the choice to use it with an interface or at the command line. OPTIONS
When using the interface you can use the following keys : LEFT ARROW decrease the volume of the current device. RIGHT ARROW increase the volume of the current device. UP ARROW go to previous device. DOWN ARROW go to next device. L locks or unlocks : unlocked : you can control the left and right channel separately. lock : left and right channel are controlled together. R turn on/off recording mode : red lamp : recording turned on green lamp : recording turned off 3 turn on/off 3D Stereo Enhancement (3DSE) device : when turned on green indicator 3D will be lit at the left side of main volume handle. A turn on/off microphone Automatic Gain Control : when turned on green indicator AGC will be lit at the left side of microphone volume handle. S save the settings of ALL devices in a file ($HOME/.camrc) G loads the saved settings and restores them. H shows the help screen. Q/ESC exits the program and returns to shell. NOTE: you can use upper or lower case. When using the command line options the interface is not shown. The following options are available : -v, --volume x,y Set 'volume' to x (left) and y (right) -b, --bass x,y Set 'bass' to x (left) and y (right) -t, --trebble x,y Set 'treble' to x (left) and y (right) -s, --synth x,y Set 'synth' to x (left) and y (right) -p, --pcm x,y Set 'pcm' to x (left) and y (right) -S, --speaker x,y Set 'speaker' to x (left) and y (right) -l, --line x,y Set 'line in' to x (left) and y (right) -m, --mic x,y Set 'microphone' to x (left) and y (right) -c, --cd x,y Set 'CD in' to x (left) and y (right) -I, --imix x,y Set 'mixer' to x (left) and y (right) -a, --altpcm x,y Set 'altpcm' to x (left) and y (right) -r, --reclev x,y Set 'record level' to x (left) and y (right) -i, --igain x,y Set 'input gain' to x (left) and y (right) -o, --ogain x,y Set 'output gain' to x (left) and y (right) -l1, --line1 x,y Set 'line 1' to x (left) and y (right) -l2, --line2 x,y Set 'line 2' to x (left) and y (right) -l3, --line3 x,y Set 'line 3' to x (left) and y (right) -3d, --3dse 1|0 Set 3D Stereo Enhancement to 1 (on) or 0 (off) -agc, --agc 1|0 Set Automatic Gain Control for microphone to 1 (on) or 0 (off) -get restore the saved values from $HOME/.camrc -save save the values to $HOME/.camrc -getfile filename restore the saved values from file 'filename' -savefile filename save the values to file 'filename' -h, -?, --help displays help NOTE: x and y are in range from 1 to 100. Higher or lower numbers are ignored. BUGS
None known as yet. If you find one, please let me know. AUTHOR
Jan 'TWP' VANDENBERGHE <jvdbergh@uia.ua.ac.be> cam(1)
All times are GMT -4. The time now is 03:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy