Sponsored Content
Top Forums Shell Programming and Scripting Add text to file at a certain line Post 69852 by Just Ice on Wednesday 20th of April 2005 08:52:23 PM
Old 04-20-2005
Quote:
Originally Posted by bhargav
Code:
sed -e '$ d' myfile >x
echo "your text" >>x
sed -n '$ p' myfile >>x

mv x myfile

... you would need to do a "chmod a+x" after the "mv" to keep the executable bit on the file ... as well as a "chown" if you're not the original owner of the file ... doing the "cat" line instead fixes these issues ...
Code:
root_icebox:/tmp # cp -p /root/nist.time .
root_icebox:/tmp # ls -l nist.time
-rwxr-xr-x   1 root     other        344 Apr  4 00:53 nist.time
root_icebox:/tmp # chown bin:bin nist.time
root_icebox:/tmp # ls -l nist.time
-rwxr-xr-x   1 bin      bin          344 Apr  4 00:53 nist.time
root_icebox:/tmp # echo "#! /bin/ksh\nhostname\ndate\nexit 0" > mytest
root_icebox:/tmp # ls -l mytest
-rw-r--r--   1 root     other         33 Apr 20 20:41 mytest
root_icebox:/tmp # mv mytest nist.time
root_icebox:/tmp # ls -l nist.time mytest
mytest: No such file or directory
-rw-r--r--   1 root     other         33 Apr 20 20:41 nist.time
root_icebox:/tmp # cp -p /root/nist.time .                            
root_icebox:/tmp # ls -l nist.time                                    
-rwxr-xr-x   1 root     other        344 Apr  4 00:53 nist.time
root_icebox:/tmp # echo "#! /bin/ksh\nhostname\ndate\nexit 0" > mytest
root_icebox:/tmp # ls -l mytest                                       
-rw-r--r--   1 root     other         33 Apr 20 20:47 mytest
root_icebox:/tmp # chown bin:bin nist.time                            
root_icebox:/tmp # ls -l nist.time
-rwxr-xr-x   1 bin      bin          344 Apr  4 00:53 nist.time
root_icebox:/tmp # cat mytest > nist.time                             
root_icebox:/tmp # ls -l nist.time mytest
-rw-r--r--   1 root     other         33 Apr 20 20:47 mytest
-rwxr-xr-x   1 bin      bin           33 Apr 20 20:48 nist.time
root_icebox:/tmp #

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a comment line in a text file

Hi I need to add a comment line at the begining of a text file. The scenario is given below. 1. The number of servers that needs to be updated is around 80 2. The location of the text file in all the servers are the same including the file name. 3. The comment has to be added at the very... (2 Replies)
Discussion started by: orakhan
2 Replies

2. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies

3. Shell Programming and Scripting

how to add line numbers in text file

Hi all How to add line numbers in text file.. ex abcd cdef result 1. abcd 2. cdef thx in advance (4 Replies)
Discussion started by: suryanarayana
4 Replies

4. Shell Programming and Scripting

Add one text line in the head of the file

hello, how can I add one text line string at the line number one of a file. thankx, (5 Replies)
Discussion started by: Ahmed waheed
5 Replies

5. Shell Programming and Scripting

Add ; to every line in text file

Please help to add ; to every line in a text file i Have tired sed 's/$/ ; /g' > /tmp/drop_tables.sql but not working :( Thanks (2 Replies)
Discussion started by: bluebird5m
2 Replies

6. Shell Programming and Scripting

sed add after line x new text from file

I've been playing with sed, trying to get it to insert the contents of somefile.txt after line 13 on anotherfile.txt. I tried searching for a line with regex and attempting to insert something on the next line with: find ./anotherfile.txt -type f -exec sed -i -e '/^dog/cat/' {} \; but it... (2 Replies)
Discussion started by: unclecameron
2 Replies

7. Shell Programming and Scripting

add serial number begining of each line in a text file

Dear All, i am having text file below rama 123 done raju 456 not done keshav 123 done ............... ............ i want to add a serial number to this file, the output should be 1 rama 123 done 2 raju 456 not done 3 keshav 123 done 99 ............... 100 ............ ... (3 Replies)
Discussion started by: suryanarayana
3 Replies

8. Shell Programming and Scripting

how to add text into the last line of text file

I need help with insert text to the last line of text file with echo command I know can do something like echo "i4\n$logtext\n.\nwq" | ex -s $file can insert to first line, but how can i change this code in order to insert to the last line of text file? please help, thank you :( (2 Replies)
Discussion started by: gavin_L
2 Replies

9. Shell Programming and Scripting

How to add line numbers (multiples of 5: 0,5,10,15,20) to a text file?

Hi, I need to number the lines in my text file. I know how to do this with standard numbering (1,2,3,4, etc) but I need to count in multiples of 5, beginning 0,5,10,15... example existing file: abcd efg hijklm nopqrs desired output 0 abcd 5 efg 10 hijklm 15 ... (11 Replies)
Discussion started by: livbaddeley
11 Replies

10. Shell Programming and Scripting

How to add the line to previous line in | delimited text?

Hi All, I am new to Unix and I have one challenge and below are the details. I have pipe delimited text file in that data has span into multiple lines instead of single line. Sample data. Data should be like below for entire file. 41|216|398555|77|provided complete NP outcome data ... (21 Replies)
Discussion started by: Narasimhasss
21 Replies
WRJPGCOM(1)						      General Commands Manual						       WRJPGCOM(1)

NAME
wrjpgcom - insert text comments into a JPEG file SYNOPSIS
wrjpgcom [ -replace ] [ -comment text ] [ -cfile name ] [ filename ] DESCRIPTION
wrjpgcom reads the named JPEG/JFIF file, or the standard input if no file is named, and generates a new JPEG/JFIF file on standard output. A comment block is added to the file. The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. Although the standard doesn't actually define what COM blocks are for, they are widely used to hold user-supplied text strings. This lets you add annotations, titles, index terms, etc to your JPEG files, and later retrieve them as text. COM blocks do not interfere with the image stored in the JPEG file. The maximum size of a COM block is 64K, but you can have as many of them as you like in one JPEG file. wrjpgcom adds a COM block, containing text you provide, to a JPEG file. Ordinarily, the COM block is added after any existing COM blocks; but you can delete the old COM blocks if you wish. OPTIONS
Switch names may be abbreviated, and are not case sensitive. -replace Delete any existing COM blocks from the file. -comment text Supply text for new COM block on command line. -cfile name Read text for new COM block from named file. If you have only one line of comment text to add, you can provide it on the command line with -comment. The comment text must be sur- rounded with quotes so that it is treated as a single argument. Longer comments can be read from a text file. If you give neither -comment nor -cfile, then wrjpgcom will read the comment text from standard input. (In this case an input image file name MUST be supplied, so that the source JPEG file comes from somewhere else.) You can enter multiple lines, up to 64KB worth. Type an end-of-file indicator (usually control-D) to terminate the comment text entry. wrjpgcom will not add a COM block if the provided comment string is empty. Therefore -replace -comment "" can be used to delete all COM blocks from a file. EXAMPLES
Add a short comment to in.jpg, producing out.jpg: wrjpgcom -c "View of my back yard" in.jpg > out.jpg Attach a long comment previously stored in comment.txt: wrjpgcom in.jpg < comment.txt > out.jpg or equivalently wrjpgcom -cfile comment.txt < in.jpg > out.jpg SEE ALSO
cjpeg(1), djpeg(1), jpegtran(1), rdjpgcom(1) AUTHOR
Independent JPEG Group 15 June 1995 WRJPGCOM(1)
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy