Print other records along with condition too


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print other records along with condition too
# 1  
Old 07-12-2012
Print other records along with condition too

Hi,

I have a text file with more than 100000 records.

I used the following command


Code:
awk '{if ($3<$2) print $1"\t"$3"\t"$2"\t"$4"\t"$5}' input.txt > output.txt

But, this one is printing which satisfies the condition, which are only 1000.

I would like to get all the 100000 records in the output.txt.

How do I do it?

thanks
# 2  
Old 07-12-2012
Just remove the condition?
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-12-2012
Let's think this through. The awk code eliminates records. You want to add them all back in. Then why run the awk code in the first place? Or?

What is your expected output in the file?
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 07-12-2012
Well, the input file is this way

Code:
abc 1 2 g h i
abc 1 3 k i l
abc 2 3 j k l
abc 3 2 m n o
abc 4 3 g b n

I want to make this input into

Code:
abc 1 2 g h i
abc 1 3 k i l
abc 2 3 j k l
abc 2 3 m n o
abc 3 4 g b n

Thanks for ur time.
# 5  
Old 07-12-2012
Try something like:
Code:
awk '$3<$2{$0=$1" "$3" "$2" "$4" "$5}1'

or
Code:
awk '$3<$2{c=$2; $2=$3; $3=c}1' infile

Do you want the fields TAB separated, or space separated?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter duplicate records from csv file with condition on one column

I have csv file with 30, 40 columns Pasting just three column for problem description I want to filter record if column 1 matches CN or DN then, check for values in column 2 if column contain 1235, 1235 then in column 3 values must be sequence of 2345, 2345 and if column 2 contains 6789, 6789... (5 Replies)
Discussion started by: as7951
5 Replies

2. Shell Programming and Scripting

Getting the records once condition met

Hi All, Seeking for your assistance to get the records once the $2 met the condition. Ex. file 1.txt 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 123232,11-Aug-2015 08:33:37 PM,4234324,1321432,34364 Output: 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 What i did... (5 Replies)
Discussion started by: znesotomayor
5 Replies

3. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies

4. Shell Programming and Scripting

Deleting the records based on the condition

Hi, Can any one help me, in deleting the records from the database table based on the following condition: script should take a configurable parameter as input. The input is nothing but “no. of years”. For example, if I enter 2 as input parameter, then the 2 year old records should get... (2 Replies)
Discussion started by: zxcjggu708
2 Replies

5. Shell Programming and Scripting

Delete records within a file upon a condition

Hi Friends, I have the following file, cat input chr1 1000 2000 chr1 600 699 chr1 701 1000 chr1 600 1710 chr2 900 1800 Now, I would like to see the difference of Record1.Col2 - Record2.Col2 Record1.Col2 - Record2.Col3 Record1.Col3 - Record2.Col2 Record1.Col3 - Record2.Col3 ... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

6. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

7. UNIX for Dummies Questions & Answers

Delete records from a big file based on some condition

Hi, To load a big file in a table,I have a make sure that all rows in the file has same number of the columns . So in my file if I am getting any rows which have columns not equal to 6 , I need to delete it . Delimiter is space and columns are optionally enclosed by "". This can be ... (1 Reply)
Discussion started by: hemantraijain
1 Replies

8. Shell Programming and Scripting

Apply condition on fixed width file and filter records

Dear members.. I have a fixed width file. Requirement is as below:- 1. Scan each record from this fixed width file 2. Check for value under field no "6" equals to "ABC". If yes, then filter this record into the output file Please suggest a unix command to achieve this, my guess awk might... (6 Replies)
Discussion started by: sureshg_sampat
6 Replies

9. UNIX for Dummies Questions & Answers

print records where an ID appears more than once

Hi everyone! I have something like the following records in a file: ID: 1 Name: A Age: 23 ID: 2 Name: B ID: 1 Activity: Climbing ID: 3 Name: C ID: 3 Activity: Skating I want to capture the records where the field Age exists AND the records that have the same ID as the one... (4 Replies)
Discussion started by: Atrisa
4 Replies

10. Shell Programming and Scripting

Printing records which meet condition using awk

Below is the code nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file I want the records from file whose 1st and 2nd field should be either "abc" or "null" I tried but its giving error. Appreciate help (2 Replies)
Discussion started by: pinnacle
2 Replies
Login or Register to Ask a Question