Checking the required columns in File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking the required columns in File
# 1  
Old 11-04-2011
Checking the required columns in File

Hello Experts,

File contains 10 columns with | delimeter. 1,3,4,5,7,9 columns are required columns means it should contains values.
i need those records, rest of it will contain or not contain data.

test1.txt:
Code:
a@a.com|a|b|c|d|e|f|g|h|i
|a|b|c|d|e|f|g|h|i
b@b.com|a||c|d|e|f|g|h|i
b@b.com|a||c|d|e|f|g||i

output:
Code:
a@a.com|a|b|c|d|e|f|g|h|i
|a|b|c|d|e|f|g|h|i

Please help me unix command

Thanks,
Murali

Last edited by Franklin52; 11-04-2011 at 05:53 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 11-04-2011
Code:
nawk -F\| '$1~/./ && $3~/./ && $5~/./ && $7~/./ && $9~/./' inputfile

# 3  
Old 11-04-2011
Thanks for your great help...

---------- Post updated at 02:28 AM ---------- Previous update was at 02:19 AM ----------

And also ,i want check the exact 10 columns,it is exceded no need to process.
# 4  
Old 11-04-2011
Code:
nawk -F\| 'NF==10 && $1~/./ && $3~/./ && $5~/./ && $7~/./ && $9~/./' inputfile

# 5  
Old 11-04-2011
it's woking Lot of thanks...

---------- Post updated at 06:51 AM ---------- Previous update was at 03:14 AM ----------

IF i use the same command,we will get the output. Using the ksh script how to load data into another file...
# 6  
Old 11-04-2011
Do you mean how to put the output into a file? Just redirect it:
Code:
nawk -F\| 'NF==10 && $1~/./ && $3~/./ && $5~/./ && $7~/./ && $9~/./' inputfile > outputfile

# 7  
Old 11-04-2011
I want create the test.ksh file using the above command and store the output file into another file.

---------- Post updated at 07:14 AM ---------- Previous update was at 07:01 AM ----------

Please help me how to do....

---------- Post updated at 07:47 AM ---------- Previous update was at 07:14 AM ----------

Any updates?

---------- Post updated at 09:48 AM ---------- Previous update was at 07:47 AM ----------

Please help me ,how to write script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print multiple required columns dynamically in a file using the header name?

Hi All, i am trying to print required multiple columns dynamically from a fie. But i am able to print only one column at a time. i am new to shell script, please help me on this issue. i am using below script awk -v COLT=$1 ' NR==1 { for (i=1; i<=NF; i++) { ... (2 Replies)
Discussion started by: balu1234
2 Replies

2. UNIX for Dummies Questions & Answers

Best Alternative for checking input parameter contains required value or not

Any good way to check if code has the required output # /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts net.ipv4.icmp_echo_ignore_broadcasts = 1 /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "= 1" net.ipv4.icmp_echo_ignore_broadcasts = 1 What I can think of is above, and it... (16 Replies)
Discussion started by: alvinoo
16 Replies

3. Shell Programming and Scripting

Checking the CSV File Columns

Hi All, i have a CSV file like below, col1 col2 col3 col4 col5 col6 col7 a1 a2 a3 a4 a5 a6 a7 b1 b2 b3 b4 b5 b6 b7 c1 c2 c3 c4 c5 c6 c7 d1 d2 d3 d4 d5 d6 d7 Col1,col2.. are the column names and... (1 Reply)
Discussion started by: dileep_d10
1 Replies

4. Shell Programming and Scripting

Required help to print diff columns for 2 patterns using awk

Hi All, I need help for below scenario : I have a principals.xml_24092012backup file : cat principals.xml_24092012backup </user> <user username="eramire" password="2D393C01720749256303D204826A374D9AE9ABABBF8A"> <roleMapping rolename="VIEW_EVERYTHING"/> </user> ... (2 Replies)
Discussion started by: kiran_j
2 Replies

5. Shell Programming and Scripting

Checking for ranges based on 2 columns

Hi, I have a file with 6 columns. I want to check if column 1 and 2 fall between column 5 and 6 I want to call them as "TRUE_genes" if not then call them as "FALSE_genes". I can do it for checking one column but how to mention about two columns. file1 110371373... (1 Reply)
Discussion started by: Diya123
1 Replies

6. Shell Programming and Scripting

Checking required columns in the file

Hi, File contains with TAB delimeter file,i want check the 2,3 are not null test1@gmail.com 100 test test2@gmail.com 101 test test3@gmail.com test test4@gmail.com 102 OUTPUT test1@gmail.com 100 test test2@gmail.com 101 test Please help me with one single command in... (2 Replies)
Discussion started by: muralikri
2 Replies

7. Shell Programming and Scripting

Checking the case of columns

Hi, Is there a function in awk or sed which will check the case of the columns. If my column 8 is in lower case then I want to change my column 10 data in lower case and vice versa. I know in awk we have tolower and toupper functions but can we manipulate the data based on the case ?? ... (3 Replies)
Discussion started by: mora
3 Replies

8. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

9. Shell Programming and Scripting

grep required data from two columns

hello, I have output from a command and I need to filter some info out of that. I tried awk command but I can not grep what I am looking for: Following is the output and I need to capture "disabled" for each volume from first column and report: # vol status Volume State ... (2 Replies)
Discussion started by: za_7565
2 Replies

10. Shell Programming and Scripting

shell script required to convert rows to columns

Hi Friends, I have a log file as below siteid = HYD spc = 100 rset = RS_D_M siteid = DEL spc = 200 rset = RS_K_L siteid = DEL2 spc = 210 rset = RS_D_M Now I need a output like column wise as below. siteid SPC rset HYD 100 RS_D_M (2 Replies)
Discussion started by: suresh3566
2 Replies
Login or Register to Ask a Question