Entering a newline into a header in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Entering a newline into a header in awk
# 1  
Old 06-13-2014
Entering a newline into a header in awk

I want to create a header with awk like this:

Code:
gawk 'BEGIN {print "List of Events"}

Desired output:

List of Events

Tennis
Baseball

But I am at a loss on how to do this. I can make a list like this:

List of Events
Tennis
Baseball

But I can't get a space to appear. I have tried to use " " and '\n'. Does anyone have any ideas? I just want to know how to make a new blank line under the header
# 2  
Old 06-13-2014
Code:
gawk 'BEGIN {print "List of Events" ORS}

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 06-13-2014
Also
Code:
nawk 'BEGIN {print "List of Events" "\n"} {print $0}' file
List of Events
 
Tennis
Football
 
cat file
Tennis
Football

This User Gave Thanks to Makarand Dodmis For This Post:
# 4  
Old 06-16-2014
This can also be done without awk

Try :

Code:
$ echo "Your Header" | cat - inputfile  > outputfile

# 5  
Old 06-16-2014
Or use group command:
Code:
{ printf "List of Events\n\n"; cat infile; } > outfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use awk to turn character to newline then scan output

i have a datafile (data.txt) that has the following data: #Beginner`echo... (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

awk delete newline after other replacements

Dear All, could you please help me to remove \n characters after all other replacements have been done as in the code below: { #remove punctuation and starting whitespaces gsub("]"," "); $1=$1; } { #print lines containing 'whatever' if ($1=="whatever") {print} #print... (3 Replies)
Discussion started by: shivacoder
3 Replies

3. Shell Programming and Scripting

awk: printing newline with last column

I was trying to simplify this from what I'm actually doing, but I started getting even more confused so I gave up. Here is the content of my input file: Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,7th Period,Davis,Lucille When I do this: ... (3 Replies)
Discussion started by: nextyoyoma
3 Replies

4. Shell Programming and Scripting

Error awk: 0602-592 cannot contain a newline character

Hi guys, I'am new at this forum as well as with unix. currently iam trying to create a unix script that will write certain string of words into a file depending on certain conditions apparently i am having problems in terms of writing into the file using the awk. it returns an error ... (0 Replies)
Discussion started by: jihmantiquilla
0 Replies

5. Solaris

Login delay after entering id (40 secs) same after entering pw

Hi all, I have just installed Solaris 10 on an old Fujitsu Primepower 650 which has been wiped clean. I haven't installed anything apart from the OS yet, so the machine is 99% idle. I get long delays when logging in, first after entering the id then another long delay after entering a valid... (8 Replies)
Discussion started by: longjon
8 Replies

6. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

7. Shell Programming and Scripting

awk puts newline between fields

I have a='123, abc, def, ghi' var1=`echo $a | awk -F", " '{print RS $1}'` echo "something: $var1" which outputs something 123 how can I tell awk not to put a newline between fields? I want it to output: something: 123 (4 Replies)
Discussion started by: unclecameron
4 Replies

8. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

9. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

10. Shell Programming and Scripting

Awk error for joining records with CR/newline

Is there any way to remove carriage retuns between the records? These carriage returns are created in an excel cell by using Alt+enter, this is similar to new line... We have input records separated by TABS and have carriage returns as below: 123 456 789 ABC "1952.00" 678 "abcdef ghik... (5 Replies)
Discussion started by: acheepi
5 Replies
Login or Register to Ask a Question