To search null and char in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To search null and char in file
# 1  
Old 07-30-2013
To search null and char in file

Hi guys,

I want to know how i can search null value and character value in a feed file.
my file has Pipe delimted records.
for eg:
Code:
1|12|xxx|yyy
.
.
.
N records

I know the the which column null and char occurs does it has for eg 3rd column which i can obtain by awk $3 and

Last edited by Don Cragun; 07-30-2013 at 02:27 PM..
# 2  
Old 07-30-2013
Hi Rohit,
Your message ends in the middle of a sentence and is slightly garbled English.
If you are looking for an actual nul byte (byte with all bits set to 0) in a file, most of the text processing utilities on UNIX and Linux systems won't help much. If you are looking for a field that doesn't contain any characters, that is easy. If you want to know if the 3rd field is empty, that is easy.

Please give us a better description of what you are trying to do and show us sample output as well as sample input. (And please use CODE tags.)
# 3  
Old 07-30-2013
try:
Code:
awk '{n=c=0; for (i=1; i<=NF; i++) {if (!$i) n++; if ($i ~ /^[A-Za-z][A-Za-z]*$/) c++}} n && c' FS="|" infile

# 4  
Old 07-30-2013
my file contains records with pipe delimited where in i need to find the nth column for eg 3rd column which either contains null or character string value and print the entire row in another file.

for eg:
Code:
file:
xx|y|3|zzz|n
yy|zz|hello|n
zzz|nnnn||x
.
.

output file:
yy|zz|hello|n
zzz|nnnn||x

# 5  
Old 07-30-2013
Code:
awk -F"|" -v COL=3 '$COL == ""' inputfile > outputfile

# 6  
Old 07-30-2013
Hi,

the above would work for null and wat about for character field
# 7  
Old 07-30-2013
Quote:
Originally Posted by rohit_shinez
my file contains records with pipe delimited where in i need to find the nth column for eg 3rd column which either contains null or character string value and print the entire row in another file.

for eg:
Code:
file:
xx|y|3|zzz|n
yy|zz|hello|n
zzz|nnnn||x
.
.

output file:
yy|zz|hello|n
zzz|nnnn||x

The "3" in the 3rd field in your first input line is a character string (just like "hello" is a character string in your second input line).
  1. Are you saying that you don't want to copy any line with any numeric characters in the third field?
  2. Are you saying that you don't want to copy any line unless there is at least one alphabetic character in the third field?
  3. Is there some other criteria I haven't guessed that explains which lines are to be copied to the output? If so, what is that criteria?

Last edited by Don Cragun; 07-30-2013 at 03:08 PM.. Reason: fix typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a certain char and insert new text if a match found

Have a file which has the create statement like below create table emp ( empno integer, empname char(50)) primary index(empno); i need to find a string starting with create and ends with semi-colon ;. if so insert the below statement before create statement rename table emp to emp_rename;... (2 Replies)
Discussion started by: Mohan0509
2 Replies

2. Shell Programming and Scripting

To search distinct special char in file

hi, i need to search distinct special character from a file which is a pipe delimited from a specific column for eg: input file.txt aa|bb|cc|$abc aa|bb|ccc|#abol bb|xss|ddd|$xyz nn|yyy|qqq|=qqqq abe|qqq|yyy|=aaa aaa|yyy|zzzz|#aaaa . . . my desired output $ (10 Replies)
Discussion started by: rohit_shinez
10 Replies

3. Shell Programming and Scripting

To find char field and replace null

hi, i having a file with | seperated in which i need to search char in 3rd column and replace with null. i need to replace only the coulmn where character occurs in 3rd field for eg: file1.txt xx|yy|xx|12 output file: xx|yy||12 (5 Replies)
Discussion started by: rohit_shinez
5 Replies

4. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

5. Shell Programming and Scripting

NULL Search String & File Name

Hi All, I am writting a Sell Script, that takes Search String & File Name from the terminal and check for Null Status. If either is NULL then pgm should quit. I wrote the following: bash-3.2$ cat null_status_of_parameters.sh #!/bin/sh #WASS that takes Search String & File Name from... (2 Replies)
Discussion started by: manishdivs
2 Replies

6. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

7. Shell Programming and Scripting

grep : search a long char contain space

Hi, i have to search for a char like that : export var1="i am not happy /not happy" with a command like : grep $var1 file but this not working with me !!! thank you in advance. (2 Replies)
Discussion started by: tizilfin
2 Replies

8. Shell Programming and Scripting

null or other char validation

I have function based out of parameter in file as below Getheaderline() { v_file='ls -lrt | grep -v "^d" | awk '{print $9}'| grep -v "^$"` export v_file cd $DATDIR PCDIR=`pwd` echo "current directory = "$PCDIR line1=`sed '1q' $v_file` v_col1=`echo $line1 | awk -F"," '{print $1}'`... (2 Replies)
Discussion started by: u263066
2 Replies

9. UNIX for Advanced & Expert Users

Using egrep to search for Text and special char

Anyone is well-versed to use egrep to search a file for a line containing both: 1) AAA 2) $ I am having problem escaping the dollar sign when using egrep in conjunction with satisfying AAA as well. E.g. Text file Line 1 AAA Line 2 $$$ Line 3 AAA BBB $ Line 4 $$$ BBB AA will return me... (2 Replies)
Discussion started by: izy100
2 Replies

10. UNIX for Dummies Questions & Answers

Search based on 1st char of a row.

I want to search for the very first character in a row from the file. It is very similar to the way we use Mainframes File-Aid, quick search option. I couldnt find anything helpful with the grep command. Does any one has an idea, how to perform this? (6 Replies)
Discussion started by: videsh77
6 Replies
Login or Register to Ask a Question