Sponsored Content
Top Forums Shell Programming and Scripting Script to find blank records in a file except for few columns Post 302945000 by chatwithsaurav on Monday 25th of May 2015 07:30:00 AM
Old 05-25-2015
Script to find blank records in a file except for few columns

I have a file with the following format:
Code:
X|High|2|GIC|DM||XHM|||6 Months  
X|Moderate|2|GIC|DM||XHM|||6 Months  
X|High|2|GCM|DM||XSF|||6 Months  
X|Med|2|GCM|DM||XSF|||6

Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th column which will remain blank by default in each row(s)). Records are separated by "| " delimiter

I tried this :
Code:
awk -F'|' '{ 
for (i=1; i<=NF; ++i) 
{ 
if($i == 6 || $i == 8 || $i == 9) 
{ 
$i++;continue; 
} 
elseif ($i ~ /^[[:space:]]*$/) 
{print NR, $0; next}}' file.txt

But it says that "awk" is unable to parse the command. Can someone help in modifying it?

Last edited by Scrutinizer; 05-25-2015 at 12:01 PM.. Reason: additional code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing blank columns from a file

Hi, I have a sample file as shown below -- id parent name dba -----------------------------------... (7 Replies)
Discussion started by: sumirmehta
7 Replies

2. Shell Programming and Scripting

Extract columns from a file if the name dont exist put blank

Hi, I am very new to Unix script. Suppose i have a file with column header: NAME1 NAME2 Address Tel And I always need to make a file with column header: ID NAME1 NAME2 EMail Address Tel For the columns that do not exist in the file, I would still like to make a column with blank. ... (11 Replies)
Discussion started by: nightrider
11 Replies

3. Shell Programming and Scripting

copying selected records from two columns to another file

Hey guys I have got a tab-separated file and I want to copy only selected records from two columns at a time satisfying specified condition, and create a new file. My tab separated file is like this ID score ID score ID Score ID score ID score 1_11 0.80 2_23 0.74 2.36 0.78 2_34 0.75 A_34... (9 Replies)
Discussion started by: jacks
9 Replies

4. Shell Programming and Scripting

Awk script to replace null columns with blank

I have a file with contents "08011"||20080812 "23348"|20080827|20080924 "23387"|20080829|20080915 "23581"|20081003|20081028 "23748"|20081017|20090114 "24095"|20080919|20081013 "24105"|20070723|20070801 "24118"|20080806|20081013 "24165"|20080820|20080912 "24221"|20080908|20080929 i... (3 Replies)
Discussion started by: sonam273
3 Replies

5. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

How to sort a text file if certain columns are blank?

Dear all, I am trying to sort a text file based on column 3, 10, 11 and 12. But certain column are blank for some lines. Column 3 has to be in ascending order after sorting. Part of my input file is as follows: CN727990 1 A01 4703 5083 73.28 - A_scaffold000011 4365605 4365985 73.28 +... (10 Replies)
Discussion started by: huiyee1
10 Replies

7. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

8. Shell Programming and Scripting

Remove blank columns from a tab delimited text file

Hello, I have some tab delimited files that may contain blank columns. I would like to delete the blank columns if they exist. There is no clear pattern for when a blank occurs. I was thinking of using sed to replace instances of double tab with blank, sed 's/\t\t//g' All of the examples... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

9. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

10. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies
pwi2xsf(1)							     XCrySDen								pwi2xsf(1)

NAME
pwi2xsf - convert the pw.x input file to XSF format SYNOPSIS
pwi2xsf [-r] file DESCRIPTION
pwi2xsf extracts the atomic structure from pw.x input file and prints the XSF formated structure data to standard output. It is a utility program of xcrysden package (http://www.xcrysden.org/) and XSF is the native xcrysden structure format (http://www.xcrys- den.org/doc/XSF.html). If file is specified as "-" then standard input is read. OPTION
-r For old pw.x versions < 1.2 one must spefify the ityp-->nat conversion and the corresponding data are writen to file nuclei.charges. The -r flag deletes this file as to force new ityp-->nat specification. COPYRIGHT
Copyright (C) 1996--2012 Anton Kokalj This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. XCrySDen March 9, 2012 pwi2xsf(1)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy