Grep last N characters of each line in a file

Karthik207

I have a file with millions of lines.And each line ends with a format say "XXX:some value" .. I want to grep only this word "XXX:some value" from each line and put it in a separate file.How can i achieve this using grep command?

PS: "some value" can be any string

Jotne

To get last n characters of each line using awk:

cat file
asdf
asdfg
asdfgh

awk -vn=2 '{print substr($0,length($0)-n+1)}'
df
fg
gh

Or do you like to get data after XXX, then do:

echo "here is my line XXX:22" | awk -F"XXX:" '{print $2}'
22

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Write first 10 characters of each line to new file using bash

분류에서Dev

How to optimize the reading of a file removing all the line feed \n characters

분류에서Dev

How to read lines of a text file with specific word to an array and get the first four characters of the last line in that array?

분류에서Dev

Each grep result to different file

분류에서Dev

What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

분류에서Dev

How to tail/grep/awk the last N bytes of a file, rather than lines

분류에서Dev

How to move the last line in a file?

분류에서Dev

Extract specific characters from each line

분류에서Dev

Bash - pair each line of file

분류에서Dev

How can I trim the last two characters of each key in an array?

분류에서Dev

How to grep a specific line _and_ the first line of a file?

분류에서Dev

How to [constantly] read the last line of a file?

분류에서Dev

How to Remove last comma of each line on csv using linux

분류에서Dev

How to Remove last comma of each line on csv using linux

분류에서Dev

remove characters from a list and add a line break from each element

분류에서Dev

Frequency of specific symbols on each line of a text file

분류에서Dev

Number of same line in each text file

분류에서Dev

Add and number blank line above each line in a file

분류에서Dev

How to Read string from file and compare to each line of second file

분류에서Dev

Using a shell script to add a ‘</pre>’ after the last line in a large file

분류에서Dev

How can I remove text on the last line of a file?

분류에서Dev

remove the first 15 characters from every other line in a file

분류에서Dev

Curl url txt file, but grep each url separately from single file

분류에서Dev

file.each_line can only be called once

분류에서Dev

Command Line, File Name for each script executed. SQL

분류에서Dev

Sort words on each line, editing the file in-place

분류에서Dev

spread a file into multiple .csv files per each line of inputfile read

분류에서Dev

grep skip n lines of file and only search after

분류에서Dev

how to delete the last line in a text file with 100M lines without having to rewrite the whole file?

Related 관련 기사

  1. 1

    Write first 10 characters of each line to new file using bash

  2. 2

    How to optimize the reading of a file removing all the line feed \n characters

  3. 3

    How to read lines of a text file with specific word to an array and get the first four characters of the last line in that array?

  4. 4

    Each grep result to different file

  5. 5

    What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

  6. 6

    How to tail/grep/awk the last N bytes of a file, rather than lines

  7. 7

    How to move the last line in a file?

  8. 8

    Extract specific characters from each line

  9. 9

    Bash - pair each line of file

  10. 10

    How can I trim the last two characters of each key in an array?

  11. 11

    How to grep a specific line _and_ the first line of a file?

  12. 12

    How to [constantly] read the last line of a file?

  13. 13

    How to Remove last comma of each line on csv using linux

  14. 14

    How to Remove last comma of each line on csv using linux

  15. 15

    remove characters from a list and add a line break from each element

  16. 16

    Frequency of specific symbols on each line of a text file

  17. 17

    Number of same line in each text file

  18. 18

    Add and number blank line above each line in a file

  19. 19

    How to Read string from file and compare to each line of second file

  20. 20

    Using a shell script to add a ‘</pre>’ after the last line in a large file

  21. 21

    How can I remove text on the last line of a file?

  22. 22

    remove the first 15 characters from every other line in a file

  23. 23

    Curl url txt file, but grep each url separately from single file

  24. 24

    file.each_line can only be called once

  25. 25

    Command Line, File Name for each script executed. SQL

  26. 26

    Sort words on each line, editing the file in-place

  27. 27

    spread a file into multiple .csv files per each line of inputfile read

  28. 28

    grep skip n lines of file and only search after

  29. 29

    how to delete the last line in a text file with 100M lines without having to rewrite the whole file?

뜨겁다태그

보관