Script to check and copy column entries


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check and copy column entries
# 1  
Old 02-21-2016
Script to check and copy column entries

Hi

I have a text file (INPUT.TXT) of three columns assuming they are separated by tab. The format is given as:

Code:
Column1       Column2      Column3
aaa           NO           aaa
bbb           YES          asdf
ccc           YES          yyasdf
ddd           NO           ddd
eee           NONE         eee
fff           YES          zzzaa
ggg           NONE         ggg
.....         .......      .....
.....         .......       .....

I need to write a script to check Column2 entry in such a way that if it is NO or NONE, copy Column1 entry to Column 4 and copy Column 3 entry if it is a YES to Column 4 in the corresponding rows.

The sample output (OUTPUT.TXT) is given below:


Code:
Column1       Column2      Column3      Column4
aaa           NO           aaa          aaa
bbb           YES          asdf         asdf
ccc           YES          yyasdf       yyasdf
ddd           NO           ddd          ddd
eee           NONE         eee          eee
fff           YES          zzzaa        zzzaa
ggg           NONE         ggg          ggg
.....        .......        .....       ....
.....        .......        .....       ....

Any help is appreciated. Thanks a lot. Smilie

Last edited by my_Perl; 02-21-2016 at 05:53 PM.. Reason: Editing
# 2  
Old 02-21-2016
After more than 100 posts, we would hope that you are starting to learn from the help the volunteers here have provided on your earlier questions.

What code have you written to try to solve this problem on your own?

And, as always, what operating system and shell are you using?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-21-2016
I use ubuntu 14.01 lts and bash shell. Thanks.
# 4  
Old 02-21-2016
I repeat:
Quote:
What code have you written to try to solve this problem on your own?
Please show us the code that you have written trying to solve this problem.
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 copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

Shell script which will check the target file and folder exists and copy it

Hi All, I am a beginner in this and trying to write a shell script in linux which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder... (3 Replies)
Discussion started by: ashish_neekhra
3 Replies

3. Shell Programming and Scripting

Script to check for null values in a column

Hi Guys, I am new to shell script.I need your help to write a shell script. I have a csv file which has 13 columns separated by , I have written below script to fetch required 5 columns. awk -F, '(NR==1){h3=$3;h4=$4;h8=$8;h9=$9;h13=$13;next}(NF>1) \ {print... (5 Replies)
Discussion started by: Vivekit82
5 Replies

4. Shell Programming and Scripting

Automation, Copy, File Status Check --> Script(s)

All, I have to write a script to do the following requirement. There is a file called BUSINESS_DATE.TXT. This file get updated once the oracle partition created. In Oracle, Partition will be created every day. There is a seperate script scheduled to take care ORACLE partition creation. The... (3 Replies)
Discussion started by: karthi_mrkg
3 Replies

5. Shell Programming and Scripting

common entries of first column in 2 or 3 files:kindly check

Hi all, I have 3 files with such data first files second file third file I have to find common entries of first column in two ways 1) between 2 files (2 Replies)
Discussion started by: manigrover
2 Replies

6. Shell Programming and Scripting

Request to check:remove entries more than once in different column

Hi I have a file 12m 345693460 12 1234 12 1234 34 345 34 345 And I want output fiel as 12m 345693460 12 1234 34 345 hw can it be done Thanks (1 Reply)
Discussion started by: manigrover
1 Replies

7. Shell Programming and Scripting

Help on Script of Copy String from column

Hello, My DATA: PLOKIJ1234G 12 13 14 15 PLOKIJ1234E 12 13 14 15 PLOKIJ1234F 12 22 33 44 IJNUHB12346 55 66 77 88 IJNUHB12347 32 34 45 67 IJUHU345D 23 23 22 33 IJUHYG23E 11 24 23 23 IJUHYG23F 77 88 99 00 output: PLOKIJ1234 PLOKIJ1234G 12 13 14 15 PLOKIJ1234... (11 Replies)
Discussion started by: asavaliya
11 Replies

8. Shell Programming and Scripting

shell script to check permission before copy over

Hi, I am writing some shell script to check the file owner permission whether the write bit is turn on. If it is turn on it will copy the file to the destination else it will just prompt user to change the file and skipping it. However, I am starting getting loss here as I have couple of... (2 Replies)
Discussion started by: wanaka
2 Replies

9. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

10. Shell Programming and Scripting

Need a script to copy files and check

Hi all, I need a script in ksh: 1: Copy files from directory (A) to directory (B) 2: Check if files that will be copied in directory (A) have never been yet copied to (B) 3: Never copy the last created file of directory (A) This script will run on crontab. Thanks in advance for your... (1 Reply)
Discussion started by: Camaro
1 Replies
Login or Register to Ask a Question