What is the command to add heading to a file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers What is the command to add heading to a file?
# 1  
Old 11-09-2005
What is the command to add heading to a file?

Hi,
I'd like to add one line to the top of my file.
I know there is a command to be able to do it.
But I forgot ......



Please help if you can ....
# 2  
Old 11-09-2005
I don't know a specific command, but this one liner works fine in sh, bash, and tcsh (a bunch of other shells too):

Code:
( echo "Line to add" ; cat targetfile ) > tempfile ; cat tempfile > targetfile ; rm -f tempfile

Where targetfile is the file you're trying to add one line to.
# 3  
Old 11-09-2005
Code:
sed '1 i\
Line to insert here' infile > outfile

Press Enter after the \ and then continue on the next line, exactly as indicated above.

Cheers
ZB
# 4  
Old 12-02-2005
CPU & Memory adding Data in First line

existing file filename "file_one.dat"

which contains
AMITH
ARUN
ARVIND

I am adding "I LOVE PIZZA" in the first line of this file

Here it is:
echo "I LOVE PIZZA" | cat > tempfile ; cat file_one.dat >> tempfile ; mv tempfile file_one.dat

Result:
I LOVE PIZZA
AMITH
ARUN
ARVIND
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Joining Columnar heading from 2 lines

Hi, Below is the format of a report generated by a custom reporting solution. I opened the report in Notepad++ and junked data and values as in the image below. https://www.unix.com/attachment.php?attachmentid=7907&stc=1&d=1575507708 I want to convert the values to a PIPE delimited format as... (2 Replies)
Discussion started by: ramkrix
2 Replies

2. Shell Programming and Scripting

Need heading in files

Hi All, The below code is splitting the file "data.csv" into several files based on the"client_code" column. date_yyyymmdd=$(my_date "" -e"%Y%m%d") file_format="_$date_yyyymmdd.csv awk '{print $2, $3> DIR"/clients_" $1 file_out}' FS=' *; *' OFS=";" DIR="$TEMPL" file_out="_$file_format"... (3 Replies)
Discussion started by: ROCK_PLSQL
3 Replies

3. Shell Programming and Scripting

SQL Column Heading

Hi, I am selecting few columns from a table using select query in UNIX shell script ans sending the results as E-mail. But the column headings are not displayed fully. Instead it displays only a part of the heading. Please help as how to display it fully. Thanks in advance for your help. (7 Replies)
Discussion started by: pvelmuru
7 Replies

4. UNIX for Dummies Questions & Answers

Using awk to get folder name and date fields with heading

It is on the HP-Unix Output desired: Folder Name Date Folder1 Mar 18 10:00 Folder2 Mar 17 12:23 Tried with ls -ldt wp411* | awk '{print $9,"\t",$6," ",$7," "$8}' Please help me with the headings (3 Replies)
Discussion started by: Siva SQL
3 Replies

5. UNIX for Dummies Questions & Answers

Replacing "." with "GG" in a certain column of a file that has heading

Hi, all, I have a file that looks like: ## XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ## YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY #AA AB AC AD AE AF AG AH AI AJ AK AL 20 60039 60039 ... (5 Replies)
Discussion started by: kush
5 Replies

6. Shell Programming and Scripting

Script to get the heading in files along with data

Hi everyone, I have a file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10... (1 Reply)
Discussion started by: Vivekit82
1 Replies

7. Shell Programming and Scripting

Sqlplus Set Heading not Working

Hello, Could someone tell me why this still returns headings? echo "SELECT columnA from tableA group by columnA;" | sqlplus -s ${DB_CONNECT} set heading OFF | while read line do arr="$line" echo ${arr} let i=$i+1 done (2 Replies)
Discussion started by: flowervz
2 Replies

8. UNIX for Dummies Questions & Answers

Extract columns from multiple files with a file name as heading

Hi All, I have 7 files, each containing 9 columns separated by space. I want to extract the 9th columns from every file and save in a new file. The columns must be pasted next to each other. And the title of each columns should be the name of the corresponding files! Since the 3rd column is... (1 Reply)
Discussion started by: Unilearn
1 Replies

9. Shell Programming and Scripting

SQL sorrting issue, and unwanted blank line above heading

Hi, I am running a shell script on Compaq Tru64 UNIX V5.1A. I have attached the shill script with the sql script it is calling to extract some data(hyp_dta_Extr.sql), and the results. I need the file to be tab delimited. (please note that I have renamed hyp_dta_Extr.sql to hyp_dta_Extr.txt to... (1 Reply)
Discussion started by: dazz
1 Replies
Login or Register to Ask a Question