AWK script to omit top characters with dashes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK script to omit top characters with dashes
# 1  
Old 09-02-2008
AWK script to omit top characters with dashes

Hi

I have an AWK script that takes an input file and outputs it as CSV format.
The problem is its also outputting the characters at the top which are dashes(-------) and i want it to leave them out.

My script is as follows.
BEGIN {
count=1;
}

/^[^(]/ {
count+=1
if ( count > 2 ){
for (i=1; i <= NF; i = i + 1)
printf("%s,",$i);
printf("\n");
}
}

what should i change to leave out the characters at the top of the file.
Thanks.
# 2  
Old 09-02-2008
Add a condition in your awk script to print the first line NR==1 as is and filter the rest of the lines through the commands.
# 3  
Old 09-02-2008
you mean like
if(NR == 1)
{for (i=1; i <= NF; i = i + 1)
printf("%s,",$i);
printf("\n");}
....
# 4  
Old 09-02-2008
Yes something on those lines...

Code:
if (NR == 1)
   print
else {
   for (i = 1; i <= NF; i = i + 1)
      printf("%s,",$i)
   printf("\n")
}
...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to omit trailer record in a file

I am trying to omit the trailer record in a variable width file I tried using awk 'NR >1 { print prev } { prev = $0 }' filename The above command is giving output but somehow it is trimming columns from the record. For example if my record has columns A,B,C,D The awk gives output as A,B,C ... (4 Replies)
Discussion started by: abhilashnair
4 Replies

2. Shell Programming and Scripting

Request for advise on how to remove control characters in a UNIX file extracted from top command

Hi, Please excuse for posting new thread on control characters, I am facing some difficulties in removing the control character from a file extracted from top command, i am able to see control characters using more command and in vi mode, through cat control characters are not visible ... (8 Replies)
Discussion started by: karthikram
8 Replies

3. UNIX for Dummies Questions & Answers

Grepping using -w and dashes (-)

I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example: ... (1 Reply)
Discussion started by: MaindotC
1 Replies

4. Shell Programming and Scripting

script to tail file; problem with awk and special characters

Trying to use code that I found to send only new lines out of a log file by doing: while :; do temp=$(tail -1 logfile.out) awk "/$last/{p=1}p" logfile.out #pipe this to log analyzer program last="$temp" sleep 10 done Script works fine when logfile is basic text, but when it contains... (2 Replies)
Discussion started by: moo72moo
2 Replies

5. Shell Programming and Scripting

using awk to omit certain characters

I have a file called file.txt with multiple lines in them. I'm trying to remove the first 2 characters and the last 2 with awk. '.batman') '.superman') '.dragonheart') .'superduper') I tried doing the following and able to get rid of the first two characters. How do I remove the trailing... (5 Replies)
Discussion started by: zerofire123
5 Replies

6. Shell Programming and Scripting

Removing columns with dashes

My files look like this I need to remove the columns where dashes are the majority, if any of the sequences has any character in that particular position it should be removed too. The IDs and Freqs should be kept intact. Thus, the resulting file should look like this Thanks in advance (14 Replies)
Discussion started by: Xterra
14 Replies

7. Shell Programming and Scripting

Adding characters at the top of all files in directory

Hi Unix experts; I have 30000 files in a directory and am willing to do the following changes on each of them. The input files look like the following: 1 , 2 3 , 4 5 , 6 7 , 8 9 , 10 the output will have # in top 10 lines, insert space instead of comma. This looks like: ... (4 Replies)
Discussion started by: nxp
4 Replies

8. Shell Programming and Scripting

how to omit data from a file created in a script

I am using the fallowing script. this script seems to work fine except the file has data I do not wish to have. Is there away to omit that data. I will first provide the scrip and then a sample of the data the way it looks and then a sample of how I would like the data to look. Thanks for any... (3 Replies)
Discussion started by: krisarmstrong
3 Replies

9. UNIX for Dummies Questions & Answers

grep throws in dashes?

Hey guys, I'm trying to grep for two things out of a file and I got that working but why is it randomly throwing "--" in the output? Is there a simple way to get rid of them? It only seems to do it when the line above what im looking for has numbers in it. $ egrep -i -B 1... (3 Replies)
Discussion started by: kingdbag
3 Replies

10. UNIX for Dummies Questions & Answers

double dashes

function date_diff { integer _dt1=$(date_to_num ${1:?}) integer _dt2=$(date_to_num ${2:?}) integer _ndt=0 if ] then ((_ndt=_dt2-_dt1)) fi print -- $_ndt } What does double dash '--' indicate ? Can anyone please answer this (2 Replies)
Discussion started by: systemsb
2 Replies
Login or Register to Ask a Question