Exclude the header row in the file to validate


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude the header row in the file to validate
# 1  
Old 08-27-2012
Exclude the header row in the file to validate

Hi All,

File contains header row.. we need to exclude the header row...no need to validate the first row in the file.
Data in the file should take valid data(two columns)..we need to exclude the more than two columns in the file except the first line.
Code:
email|firstname
a|123|100
b|345
c|456|123|123
d|456
e    456

i need output for the file..
Code:
 email|firstname
b|345
d|456

Thanks,
# 2  
Old 08-27-2012
Something like this?
Code:
awk -F"|" 'NR==1 || NF==2' file

# 3  
Old 08-27-2012
Try this..

Code:
awk -F "|" ' { if (NR != 1) { if (NF == 2 ) { print } } else { print } }' file

# 4  
Old 08-27-2012
Million's Thanks...working fine as i excepted..

---------- Post updated at 02:43 AM ---------- Previous update was at 02:42 AM ----------

@pamu @Franklin52
Million's Thanks
# 5  
Old 08-27-2012
or Gnu sed
Code:
sed -r '/^(.[^|]*)\|(.[^|]*)$/!d' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to validate header in a csv file

Hi All; I am struggling to write a script that validates file header. Header file would be like below with TAB separated TRX # TYPE REF # Source Piece Code Destination Piece Code every time I need to check the txt file if the header was same as above fields if validation success... (6 Replies)
Discussion started by: heye18
6 Replies

2. Shell Programming and Scripting

Bash to verify and validate file header and data type

The below bash is a file validation check executed that will verify the correct header count of 10 and the correct data type in each field of the tab-delimited file. The key has the data type of each field in it. My real data has 58 headers in it but only the header and next row need to be... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

How to display the header of a matched row in a file?

Hi, So I am trying to print the first row(header) first column alongwith the matched value. But I am not sure how do I print the same, by matching a pattern located in the file eg File contents Name Place Jim NY Jill NJ Cathy CA Sam TX Daniel FL And what I want is... (2 Replies)
Discussion started by: sidnow
2 Replies

4. Shell Programming and Scripting

Exclude the header row while splitting the file

Hi All, i have script like ... "TYPE_ID" "ID" "LIST_ID" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" i am using the below code it's not taking the header row. awk -F"\t" -v file=test1.txt -v file1=test2.txt ' { if(... (7 Replies)
Discussion started by: bmk
7 Replies

5. UNIX for Dummies Questions & Answers

File Row Line Count without Header Footer

Hi There! I am saving the file count of all files in a directory to an output file using: wc -l * > FileCount.txt I get: 114 G4SXORD 3 G4SXORH 0 G4SXORP 117 total But this count includes header and footer. I want to subtract 2 from the count and get ... (7 Replies)
Discussion started by: gagan8877
7 Replies

6. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

7. Shell Programming and Scripting

Test command:Duplicate Header row in Log File

I have a script that is inventorying (not sure if thats a word) my environment. It goes out and pulls Hostname OS, IP, and ENV (dev, prod, etc)..then spits all that to a logfile At the top of my script i have a check to see if the logfile exist. ] || touch $LOGFILE && echo "ENV" "\t"... (3 Replies)
Discussion started by: nitrobass24
3 Replies

8. UNIX for Dummies Questions & Answers

append column and row header to a file in awk script.

Hi! Is there a way to append column and row header to a file in awk script. For example if I have Jane F 39 manager Carlos M 40 system administrator Sam F 20 programmer and I want it to be # name gend age occup 1 Jane F 39 manager 2 Carlos M ... (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

9. Shell Programming and Scripting

Script to validate file header and trailer

Hi, I need a script that validates a file header/detail/trailer. File layout is: Header - Rec_Type|File_name|File_Date Detail - Rec_Type|field1|field2|field3... Trailder - Rec_Type|File_name|File_Date|Record_count Sample Data: HDR|customer_data.dat|20120709... (7 Replies)
Discussion started by: ash_sh
7 Replies

10. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies
Login or Register to Ask a Question