0

How to extract specific row of file and save it in another file? I have One file with 11 rows and I want to copy only row 4 to new file. File is in csv format

EDIT

i need to copy row not line. If the solution is to copy line then i need to copy 4th place from each line to new file. On that place is a 14 digit number and all 14 digits need to be copied

user38974
  • 1
  • 1
  • 3
  • For many of us, "row" and "line" are synonymous in this context. Do you mean you want to extract a specific set of columns, by character position, or from a delimited format like CSV? Either way, it should be easy to find existing duplicates with many answers; this is a very common beginner FAQ. – tripleee Oct 23 '17 at 07:18
  • Possible duplicate of https://stackoverflow.com/questions/12452298/bash-command-to-print-column-at-specific-range-of-line-numbers – tripleee Oct 23 '17 at 07:20
  • I have file that has 11 columns. From it i need only to copy column 4 to another file and from that file extract only last 8 digits from every line and have them send to web server. – user38974 Oct 23 '17 at 07:45
  • I posted a second answer to the question I nominated as another duplicate. Since you only actually ask about the extraction, I'll leave it at that. – tripleee Oct 23 '17 at 08:20

1 Answers1

0

awk command can be used for doing this

awk 'NR == LNUM' test.txt > test2.txt

this will copy line number represented by LNUM from test.txt to test2.txt

In your case command will be

awk 'NR == 4' test.txt > test2.txt
at S
  • 73
  • 7
  • But won`t that copy line and not row? – user38974 Oct 23 '17 at 05:57
  • If you want to copy 4th column of each line then you can use this command `awk '{print $4}' test.txt > test2.txt`. It will copy 4th column of each line into test2.txt. To copy any other column just change number after $. – at S Oct 24 '17 at 05:43