Reputation: 59
I have a data in my .txt
file as below, I want to extract the line that have value as 12 and copy it into new .txt
file. I tried with sed
but could get the result, any help would be appreciated . Thanks
"944760 1939" 10
"944760 1940" 12
"946120 1940" 2
"946370 1939" 10
"946370 1940" 12
"946460 1940" 6
"946530 1939" 10
Upvotes: 5
Views: 152
Reputation: 16997
Why don't just search forum, before posting here, so many posts repeated
awk '$3 == 12' infile > outfile
which is same as
awk '$3 == 12 { print }' infile > outfile
Explanation
$3 == 12
if 3rd column is equal to 12, print such record/row Upvotes: 6
Reputation: 133760
Following simple awk
may help you on same:
awk '$NF==12{print $0 > "new_file"}' Input_file
Explanation:
$NF==12
: Checking condition here if last field's value is 12
means condition is TRUE then perform further/following statements.
{print $0 > "new_file"}
: Printing current line($0) value to a output file named
new_file
(you could change its name as per your wish too).
Input_file
: Mentioning Input_file name here.
Solution 3rd: As per karafka sir's comment adding this one too now.
awk'$NF==12' Input_file > "new_file"
Upvotes: 5