howto add line as a first line into a non empty file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting howto add line as a first line into a non empty file
# 1  
Old 05-30-2010
howto add line as a first line into a non empty file

Hi

Trying to do like this :

echo "$variable1\n $(cat file.txt)"

but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1.

How to add constantly line into first line in file ?
# 2  
Old 05-30-2010
one way:
Code:
echo "$variable" > tmpfile
cat oldfile >> tmpfile
mv tmp oldfile

# 3  
Old 05-30-2010
Code:
sed -ie '1i\
'$variable'\
' file.txt

# 4  
Old 06-03-2010
thx but how to implement this here
https://www.unix.com/shell-programmin...00-bajtow.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete everything after empty line in file

Hello, I am trying to remove everything coming after empty line under ubuntu14.04. How may I do it? file: aaa 020390 bb00id3 c03wisi 209dl x092sia 0290s I expect: aaa 020390 bb00id3 c03wisi (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

4. Programming

[SOLVED] C++ print next line until line.empty

Hi, could you please help with the following: I have an input file like: one two three four five six I want to print the lines starting from 'three' to the empty line. Something like that: if ( line == "three" ) { while ( !line.empty() ) { cout <<... (0 Replies)
Discussion started by: apenkov
0 Replies

5. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

6. Shell Programming and Scripting

Adding New empty line in a file

Hi, I am new to Sed /awk commands. using that i want to add new empty line after every line in a file by leaving first three lines. So, can any one help me out how to achieve this. Example: --------- Input Filename: file1.txt Input Data: --------Report-------- Date:20-10-03... (4 Replies)
Discussion started by: G.K.K
4 Replies

7. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

8. Shell Programming and Scripting

Add new parameters into a line, and redirect the line to other file

How can i add new parameters into a line, and redirect the line to other file? For example: 1.sh name:owner google:richard youtube:student I want a, for example 2.sh with: name:owner:description google:richard:search site youtube:student:video site In the 2.sh, I added a new column:... (7 Replies)
Discussion started by: rafazz
7 Replies

9. Shell Programming and Scripting

Checking the Empty line in csv file

Hi all, I have one CSV file(MasterFile.csv) consists of two columns. "./incoming/ABC.CSV","./incoming/ABC_CONTROL.txt" "./incoming/PQR.CSV","./incoming/PQR_CONTROL.txt" "./incoming/123.CSV","./incoming/123_CONTROL.txt" I have written a script to read the MasterFile.csv.Here i want to... (4 Replies)
Discussion started by: sollins
4 Replies

10. Shell Programming and Scripting

printing an empty line in a file (perl)

I know this must be really easy, but i can't get it to work I've got a perl script, with a file. I want to print an empty line, and the following doesn't seem to work: print nameoffile "\n" thanks for your help!! (3 Replies)
Discussion started by: kfad
3 Replies
Login or Register to Ask a Question