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
The cut command offers many ways to extract portions of each line from a text file. It's similar to awk in some ways, but it has its own advantages and quirks. One surprisingly easy command for grabbing a portion of every line in a text file on a Linux system is cut.
Use readlines() to Read the range of line from the File You can use an index number as a line number to extract a set of lines from it. This is the most straightforward way to read a specific line from a file in Python. We read the entire file using this way and then pick specific lines from it as per our requirement.
Using the head and tail Commands Let's say we want to read line X. The idea is: First, we get line 1 to X using the head command: head -n X input. Then, we pipe the result from the first step to the tail command to get the last line: head -n X input | tail -1.
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 If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With