Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have an input file which has rows of numerical digits ( close to 2000 rows )
I want to extract out " the second to the eight digit from the right" of every row of the numeric string into a separate file, with the result separated by a comma as shown.
Example:
00000000000001303275310752
00000000000001827380519015
00000000000000800081610361
00000000000000449481894004
00000000000000449481894004
00000000000001812612607514Expected result: newfile.txt
7531075,
8051901,
8161036,
8189400,
8189400,
1260751,
I'm guessing something like 'sed' can be used to solve my problem, but i'm not quite sure how to go about achieving this.
Appreciate if someone can guide me with a brief explanation.regards,
novice.

The Unix cut command should do what you want:
#!/bin/ksh
while read line do length=${#line} # get the line length f1=$(echo "$line"|cut -c$(($length-7))-$(($length-1)) ) # cut out the required columns printf "%s,\n" "$f1" done < datafile.txt > newfile.txt

Thanks mate.
I got around my problem with the following :
cut -c19-25 input.txt | sed 's/$/,/' > temp.txt

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |