How to match mandatory column in file.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to match mandatory column in file.?
# 1  
Old 12-26-2013
Question How to match mandatory column in file.?

# 2  
Old 12-26-2013
Hello Rishabh,

Could you please provide us the Input and the expected Output for same please. So that we can help you more on same.


Thanks,
R. Singh
# 3  
Old 12-26-2013
Hello Ravinder,

I am new here as well as new with linux shell scripting.I am using putty and uning c shell.

Scenario:-

input.txt
++++++++

Code:
CUST_ID    FIRST_NAME    MIDDLE_NAME    LAST_NAME    PHONE_NO    CITY
101    Jack    Min    Tim    9878898745    Delhi
102    Gan    Jh    Hu    0256546454    Tokiyo
103    Is    Uh    Jong    4687598564    Newyork

CUST_ID and FIRST_NAME is mandatory.

============================================================================================
Code:
#!/bin/ksh

  dos2unix $4

more  $4
head -4 $4|tr '\011' '|'

sed -i 's/1010//' $4


echo "hello"
if [[ $4 == inpu* && grep 'CUST_ID' inpu* &&grep 'FIRST_NAME' inpu*  ]]
    then
        echo -e "All mandatory columns are present"
    fi

++++++++++++++++++++++++++++++

This is throwing error in if condition.

Please have a look on above if conditions
1) As file is tab seprated , I would like to remove extra spaces from header of file.
2) If I use dos2unix command on a unix format file, Does it make sense?

Last edited by Franklin52; 12-27-2013 at 09:17 AM.. Reason: Please use code tags
# 4  
Old 12-26-2013
Hello,

Could you please use the code tage for same, as per forum rules which you have agreed before creating your login id.

Also kindly let us know the expected Input and expected output.


NOTE: Example for using code tags for example I am mentioning as follows.
Code:
 echo "Hello all"


Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

Match substring from a column of the second file

I want to merge the lines by matching substring of the first file with first column of the second file. file1: S00739A_ACAGTG_L001_R1.fq.gz S00739A_ACAGTG_L001_R2.fq.gz S00739B_GCCAAT_L001_R1.fq.gz S00739B_GCCAAT_L001_R2.fq.gz S00739D_GTGAAA_L001_R1.fq.gz S00739D_GTGAAA_L001_R2.fq.gz... (14 Replies)
Discussion started by: yifangt
14 Replies

3. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

4. Shell Programming and Scripting

Match column 8 in file 1 with column 2 in file 2 and replace..

I am looking at the NR==FNR posts and trying to use them to achieve the following but I am not getting it. I have 2 files. I want to match column 8 in file 1 with column 2 in file 2. When they match I want to replace column 9 in file 1 with column 1 in file 2. This is and extract from file 1 ... (5 Replies)
Discussion started by: kieranfoley
5 Replies

5. Shell Programming and Scripting

Match value in column and append file with new values

Hi, I need help to match two files based on two columns. file_1 ID AA An Ca Ele Pro Su Ot Tra g13950 No No Yes No Yes Yes Yes Yes g05760 Yes No No No No Yes Yes Yes g12640 No No No No No No No No k17720 No Yes No No No No No Yes g05640 Yes Yes Yes No No Yes Yes Yes file_2 ... (8 Replies)
Discussion started by: redse171
8 Replies

6. Shell Programming and Scripting

Match same file column data

File A B07 U51C 4434 L662C 4412 B07 L64U 612 L651B 4434 B07 L11C 4434 R151B 4434 B05 L12Z 612 L51B 4434 B01 651Z 612 L651C 4434 B04 A51Z 612 L51A 4434 L07 B08D 4434 B1B 4434 B07 RU8D 4434 L51A 4434 B07 L58D 4434 B51C 4434 B07 LA8D 4434 L4B 4434 Now i want File B Output B07... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. Shell Programming and Scripting

print when column match with other file

Hello all, please help. There are two file like this: file1: 1197510.0 294777.7 9666973.0 21.6 1839.8 1197510.0 294777.7 9666973.0 413.2 2075.9 1197510.0 294777.7 9666973.0 689.3 2260.0 ... (1 Reply)
Discussion started by: attila
1 Replies

8. Shell Programming and Scripting

print column value after exact match of variables in file

I have file like below summit hvar_rgrpd_10d_hvams17_ _kgr_prod.rec checksum checksum us europe summit hvar_rgrpd_10d_hvams17_ _kgr_prod.xml var summit us ... (5 Replies)
Discussion started by: manas_ranjan
5 Replies

9. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

10. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies
Login or Register to Ask a Question